ndegioia
asked on
Insert Multiple Variables into the same SQL Data field
Hello Experts!
I am still new to Visual Basic.NET, and I have seemed to run into an obstacle I can readily solve. Here is what I am trying to do. I am writing a custom record insertion form to generate hyperlinks and insert them in to a Database table Data field. The content of the hyperlinks need to be based on user input.
For example: <a href=http://server/[user input from textbox1]/[more user input from textbox2].pdf>[Display Text from textbox3]</a>
I have been able to insert into the target data field from a textbox a which the user has input information, and assigned it to a button to load and return the newly inserted data, however I need the whole hyperlink to be inserted into the same target data field.
I have tried to add variables in between the single quotes required to define a variable in a sql statement with the “&” and the “+”. At design time Visual Basic does not have a problem with it, but a run time it fails.
Does anybody know of an effective way to accomplish this? I need the whole hyperlink to insert into the target data field.
Here is the code I have so far:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dataset1 As New DataSet
dataset1 = New DataSet("dataset1")
Dim ConnectionString As String = "Provider=SQLOLEDB.1;Integ rated Security=SSPI;data sourc" & _
"e=LOGSOHFIL01;persist security info=False;initial catalog=MasterFileIndex"
Dim Connection1 As OleDbConnection = New OleDbConnection(Connection String)
Dim Command1 As OleDbCommand = _
New OleDbCommand("INSERT INTO test (First_Name, Last_Name, Info) values ('" & TextBox1.Text & " ', ' " & TextBox2.Text & " ', '" & TextBox3.Text & "') select* FROM test")
Command1.CommandType = CommandType.Text
Connection1.Open()
Command1.Connection = Connection1
Dim OleDbDataAdapter1 As OleDbDataAdapter = New OleDbDataAdapter
OleDbDataAdapter1.SelectCo mmand = Command1
OleDbDataAdapter1.Fill(dat aset1, "authors")
DataGrid1.SetDataBinding(d ataset1, "authors")
Connection1.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Thanks for your help!
I am still new to Visual Basic.NET, and I have seemed to run into an obstacle I can readily solve. Here is what I am trying to do. I am writing a custom record insertion form to generate hyperlinks and insert them in to a Database table Data field. The content of the hyperlinks need to be based on user input.
For example: <a href=http://server/[user input from textbox1]/[more user input from textbox2].pdf>[Display Text from textbox3]</a>
I have been able to insert into the target data field from a textbox a which the user has input information, and assigned it to a button to load and return the newly inserted data, however I need the whole hyperlink to be inserted into the same target data field.
I have tried to add variables in between the single quotes required to define a variable in a sql statement with the “&” and the “+”. At design time Visual Basic does not have a problem with it, but a run time it fails.
Does anybody know of an effective way to accomplish this? I need the whole hyperlink to insert into the target data field.
Here is the code I have so far:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dataset1 As New DataSet
dataset1 = New DataSet("dataset1")
Dim ConnectionString As String = "Provider=SQLOLEDB.1;Integ
"e=LOGSOHFIL01;persist security info=False;initial catalog=MasterFileIndex"
Dim Connection1 As OleDbConnection = New OleDbConnection(Connection
Dim Command1 As OleDbCommand = _
New OleDbCommand("INSERT INTO test (First_Name, Last_Name, Info) values ('" & TextBox1.Text & " ', ' " & TextBox2.Text & " ', '" & TextBox3.Text & "') select* FROM test")
Command1.CommandType = CommandType.Text
Connection1.Open()
Command1.Connection = Connection1
Dim OleDbDataAdapter1 As OleDbDataAdapter = New OleDbDataAdapter
OleDbDataAdapter1.SelectCo
OleDbDataAdapter1.Fill(dat
DataGrid1.SetDataBinding(d
Connection1.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Thanks for your help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER