can you help me assign sql query to gridview..i am trying like this but it doesnt work.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim con As New SqlConnection("Data Source=SPERANZA\SQLEXPRESS;initial catalog=master;integrated security=true")
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
cmd.Connection = con
con.Open()
cmd.CommandText = "SELECT name,dob,sex FROM users WHERE name LIKE ('%' + @name + '%')"
cmd.Parameters.AddWithValue("@name", txtname.Text)
dr = cmd.ExecuteReader()
GridView1.DataSource = dr
con.Close()
End Sub
and code in aspx file
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Height="176px" Width="598px">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%#Eval("name")%><br />
<%#Eval("dob")%><br />
<%#Eval("sex") %><br />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>