HOME > .NET Framework > Forum > web asp.net คือไม่รู้ว่าผิดตรงไหนอ่าคับรบกวนที Both DataSource and DataSourceID are defined on ‘GridView1′. Remove one definition.
web asp.net คือไม่รู้ว่าผิดตรงไหนอ่าคับรบกวนที Both DataSource and DataSourceID are defined on ‘GridView1′. Remove one definition.
Protected Sub Btn_Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn_Add.Click
Dim connStr As String = ConfigurationManager.ConnectionStrings("testConnectionString").ConnectionString.ToString()
Dim conn As New SqlConnection(connStr)
Dim cmd As New SqlCommand()
cmd.CommandText = "INSERT INTO Table_Roomdata(D_ID,D_NR,D_PT,D_Phon,D_PE,D_Date)" & _
" VALUES(@D_ID,@D_NR,@D_PT,@D_Phon,@D_PE,@P_Date) "
cmd.Parameters.Add("@D_ID", SqlDbType.VarChar).Value = txt_D_ID.Text
cmd.Parameters.Add("@D_NR", SqlDbType.VarChar).Value = txt_D_NR.Text
cmd.Parameters.Add("@D_PT", SqlDbType.VarChar).Value = txt_D_PT.Text
cmd.Parameters.Add("@D_Phon", SqlDbType.VarChar).Value = txt_D_Phon.Text
cmd.Parameters.Add("@D_PE", SqlDbType.VarChar).Value = txt_D_PE.Text
cmd.Parameters.Add("@D_Date", SqlDbType.DateTime).Value = DateTime.Now
cmd.Connection = conn
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
GetData()
Protected Sub GetData()
Dim CondStr As String = ""
If txt_Search.Text <> "" Then
CondStr = " and (D_ID like '" & txt_Search.Text & "%' OR D_NAME like '" & txt_Search.Text & "%')"
End If
Dim connStr As String = ConfigurationManager.ConnectionStrings("testConnectionString").ConnectionString.ToString()
Dim conn As New SqlConnection(connStr)
conn.Open()
Dim da As New SqlDataAdapter("select * from Table_Roomdata where 1=1 " & CondStr, conn)
Dim ds As New DataSet()
da.Fill(ds)
conn.Close()
GridView1.DataSource = ds
GridView1.DataBind()
txt_Count.Text = GridView1.Rows.Count.ToString()
End Sub