Four Seasons

I have a question

I tried to excute a stored procedure and I need to read the data from table.

Public Sub _GetCountryByID _

(ByVal countryID As Integer)

Dim conn As New SqlConnection

Dim findCountryCommand As New SqlCommand

conn.Open()

findCountryCommand.Connection = conn

findCountryCommand.CommandType = CommandType.StoredProcedure

findCountryCommand.CommandText = "sp_FindByID"

conn.Close()

End Sub

how can I assign sql command to the dataset



Re: Windows Forms Data Controls and Databinding sql command and the dataset

Bob zhu - MSFT

you need dataadapter as follow


Dim ds as DataSet
Dim MyConnection as SQLConnection
Dim MyAdpt as SQLDataAdapter
MyConnection =New SQLConnection("server='localhost';UID=sa;PWD=wenasen.com; database=credit_sql")
MyAdpt = New SQLDataAdapter("select * from admin",MyConnection)
ds= new DataSet()
MyAdpt.Fill(ds,"admin")
dgA.DataSource=ds.tables("admin").defaultView
dgA.DataBind()
end sub






Re: Windows Forms Data Controls and Databinding sql command and the dataset

Four Seasons

Thank you for your useful help

but I didn't understand these 2 line of code

dgA.DataSource=ds.tables("admin").defaultView
dgA.DataBind()

what do you mean exactly by dgA

thank you Bob zhu





Re: Windows Forms Data Controls and Databinding sql command and the dataset

Bob zhu - MSFT

sorry for some local info in my post,

"admin" only the table name in dataset ,you can use anything you like

dgA is DataGridView name.