I've been trying to open a connection to my sql database so i can add new rows and make edits to already existing rows. On the ~conn.Open();~ part i keep getting an expection thrown about the sqlinternalconn ection... how do i fix this code or is there something i need to change in vb or the sql server settings themselves?
Code:
string pName = textBox6.Text.Trim();
string pMobile1 = textBox5.Text.Trim();
string pHome = textBox3.Text.Trim();
string pBusiness = textBox2.Text.Trim();
string pEmail = textBox1.Text.Trim();
string pCategory = comboBox1.SelectedText.Trim();
Debug.Write("test0 ");
SqlConnection conn = new SqlConnection(
"Server = CLB125_25; Data Source = \\C:Documents and Settings\\SLU Student\\Desktop\\SmartDeviceProject1\\database1.sdf");
Debug.Write("test1 ");
SqlDataReader rdr = null;
Debug.Write("test2 ");
try
{
conn.Open();
Debug.Write("test3");
string actionString = "INSERT INTO Contacts(Name, Home_Phone, E-Mail, Address, Mobile, Category) VALUES(" + pName.ToString() + "," + pHome.ToString() + "," + pEmail.ToString() + "," + pBusiness.ToString() + "," + pMobile1.ToString() + "," + pCategory.ToString() + ")";
SqlCommand cmd = new SqlCommand(actionString, conn);
cmd.ExecuteNonQuery();
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Console.WriteLine(rdr[0]);
}
}
catch (SqlException d)
{
Console.Write(d);
}
finally
{
if (rdr != null)
{
rdr.Close();
}
if (conn != null)
{
conn.Close();
}
}
Comment