command.Parameters.AddWithValue("@number", TextBox1.Text)

can i do this from another way?


when i try to search something, program give me this error; Must declare the variable [EMAIL="'@number'"]'@number'[/EMAIL] on this line; DataGridView2.DataMember = "mutsuz".


full code is this.


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click


Dim baglanti As New SqlClient.SqlConnection()
Dim dataadapter As SqlClient.SqlDataAdapter
Dim command As New SqlClient.SqlCommand
Dim dataset As New DataSet
baglanti.ConnectionString = "data source=zengin\instance2000;" & "initial catalog=inandbf;" & "integrated security= SSPI"
baglanti.Open()
command = baglanti.CreateCommand
command.CommandText = "select number, name, surname from veriler where number=@number"
command.Parameters.AddWithValue("@number", TextBox1.Text)
dataadapter = New SqlClient.SqlDataAdapter(command.CommandText, baglanti)
dataadapter.Fill(dataset, "mutsuz")
DataGridView2.DataSource = dataset
DataGridView2.DataMember = "mutsuz"
baglanti.Close()
End Sub

Try the following intead of
command.Parameters.AddWithValue("@number", TextBox1.Text)

dataadapter.SelectCommand.Parameters.AddWithValue("@number", TextBox1.Text).

Sampiyon FeNeRbAhCe

Edited 5 Years Ago by yoteksin: duplicate

This article has been dead for over six months. Start a new discussion instead.