i need to convert this code from c# to vb.net

ethicalhacker

Well-known member
Joined
Apr 22, 2007
Messages
142
Location
Delhi,India
Programming Experience
5-10
private void ins_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Server=.; database=amit;user id=sa; password=.");
con.Open();
SqlCommand com = new SqlCommand("insert into log1 values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')", con);
com.ExecuteNonQuery();

con.Close();
}
also if I want to increase the number of columns to be inserted upto textbox7 and use an sql function in the query i get a runtime error saying the string or binary was truncated
for example if I use
SqlCommand com = new SqlCommand("insert into log1 values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "'," + "getdate()" + ")", con);

So I want 7 fields to have data taken from the 7 textboxes and the 8th field as getdate() which will insert the current date and time in the 8th field.
The above query with 8 fields just doesnt work...
 
I use Instant VB from Tangible Software Solutions and it offers this translation:

VB.NET:
Private Sub ins_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim con As SqlConnection = New SqlConnection("Server=.; database=amit;user id=sa; password=.")
con.Open()
Dim com As SqlCommand = New SqlCommand("insert into log1 values('" & textBox1.Text & "','" & textBox2.Text & "','" & textBox3.Text & "','" & textBox4.Text & "')", con)
com.ExecuteNonQuery()

con.Close()
End Sub
 
Back
Top