DataSource

M

MXC

I am new to ASP.NET

I did a simple test for set datasource.
I put a textbox, a button ans a gridview in a page
I put following code i button_click event.
It not working, Why???
I tried same code in windowsApplication(using datagridview in stead of
gridView) and working fine.

Why not working in webcontrol?


Thanks

Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim CustomerID As String
Dim strConn As String = "Data Source=MXC-PC;Initial
Catalog=Northwind;Integrated Security=True"
Dim conn As New System.Data.SqlClient.SqlConnection(strConn)
Dim da As New System.Data.SqlClient.SqlDataAdapter
Dim ds = New System.Data.DataSet 'Me.dataSet1
If conn.State = Data.ConnectionState.Closed Then conn.Open()
Try
CustomerID = (TextBox1.Text)
Dim SQL As String = "dbo.CustOrderHist" '& CustomerID
Dim cmd As New SqlCommand
cmd.CommandText = SQL
cmd.Connection = conn
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@CustomerID", CustomerID)
da.SelectCommand = cmd
da.Fill(ds)
GridView1.DataSource = Nothing
GridView1.DataSource = ds.Tables(0).DefaultView
DataList1.DataSource = ds
Catch ex As Exception
MsgBox(ex.Message)
End Try
conn.Close()
End Sub
 
M

miher

Hi,
I think You forgot to invoke DataBind method after setting DataSource.

Hope this solves Your problem.
-Zsolt
 
M

MXC

Thanks
After add databind, the problem solved.

miher said:
Hi,
I think You forgot to invoke DataBind method after setting DataSource.

Hope this solves Your problem.
-Zsolt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top