I am currently facing a problem here. I have a column called "DESC1" in a table called "Master". I'm trying to retrieve the value based on something along the lines of this...
我现在正面临一个问题。我在一个名为“Master”的表中有一个名为“DESC1”的列。我试着根据这条线来获取值。
"Select DESC1 FROM Master WHERE '" & TextBox1.Text & "' "
And I'm trying to display on the excel beside both correctString1 and correctString
我试着在excel的excel中显示正确的字符串。
oWB.Sheets(1).Range("A2", "K2").Insert(Shift:=Excel.XlDirection.xlDown)
oWB.Sheets(1).Range("E2").Value = " " & correctString1 & " : " & correctString & " "
Hope you can help me out.
希望你能帮助我。
1 个解决方案
#1
1
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()
Considering first column is NUMBER
type and second column is VARCHAR
第一列为数字类型,第二列为VARCHAR
阅读更多
==Update==
= = = =更新
connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
看到更多的
#1
1
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()
Considering first column is NUMBER
type and second column is VARCHAR
第一列为数字类型,第二列为VARCHAR
阅读更多
==Update==
= = = =更新
connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
看到更多的