如何将SQL语句存储到variables中
我目前在这里面临一个问题。 我在名为“Master”的表中有一个名为“DESC1”的列。 我试图检索基于这一点的东西的价值…
"Select DESC1 FROM Master WHERE '" & TextBox1.Text & "' "
而且我试图显示在correctString1和correctString旁边的excel
oWB.Sheets(1).Range("A2", "K2").Insert(Shift:=Excel.XlDirection.xlDown) oWB.Sheets(1).Range("E2").Value = " " & correctString1 & " : " & correctString & " "
希望你能帮助我。
Dim sqlConnection1 As New SqlConnection("Your Connection String") Dim cmd As New SqlCommand Dim reader As SqlDataReader cmd.CommandText = "Select DESC1 FROM Master WHERE '" & TextBox1.Text & "' " cmd.CommandType = CommandType.Text cmd.Connection = sqlConnection1 sqlConnection1.Open() reader = cmd.ExecuteReader() ' Data is accessible through the DataReader object here. If reader.HasRows Then Do While reader.Read() Console.WriteLine(reader.GetInt32(0) _ & vbTab & reader.GetString(1)) Loop Else Console.WriteLine("No rows found.") End If sqlConnection1.Close()
考虑第一列是NUMBER
types,第二列是VARCHAR
阅读更多
== ==更新
connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
查看更多