Hi HassanAli,
Please refer below modified code.
You have to provide SqlConnection object inside SqlCommand.
Code
C#
protected void btnInsert_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=DESKTOP-K69AE8A;Initial Catalog=fb;Integrated Security=True");
conn.Open();
SqlCommand cmd = new SqlCommand("insert into fb.dbo.signup(first name, last name, email, password, confirm password, gender) values ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox7.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "', '" + TextBox6.Text + "')", conn);
TextBox1.Text = "";
TextBox2.Text = "";
TextBox7.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
cmd.ExecuteNonQuery();
conn.Close();
}
VB.Net
Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim conn As SqlConnection = New SqlConnection("Data Source=DESKTOP-K69AE8A;Initial Catalog=fb;Integrated Security=True")
conn.Open()
Dim cmd As SqlCommand = New SqlCommand("insert into fb.dbo.signup(first name, last name, email, password, confirm password, gender) values ('" & TextBox1.Text & "','" + TextBox2.Text & "','" + TextBox7.Text & "','" + TextBox4.Text & "','" + TextBox5.Text & "', '" + TextBox6.Text & "')", conn)
TextBox1.Text = ""
TextBox2.Text = ""
TextBox7.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
cmd.ExecuteNonQuery()
conn.Close()
End Sub