Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
private void cmdAdd_Click(object sender, EventArgs e)
{
    SqlConnection myConnection = new SqlConnection();
    myConnection.Open();
   
    try
    {                
        myConnection.ConnectionString = "Data Source=ACER-LAPTOP\a2006; Database=AED_MOBILE_0; Initial Catalog=db_stuRegisterPay; Integrated Security=SSPI";
    }
    catch
    {
        Console.WriteLine(e.ToString());
    }

    SqlCommand myCommand = new SqlCommand("INSERT INTO TestInfo(TestIC, TestName, TestPhone) " + "VALUES('" + txtIC.Text + "','" + txtName.Text + "','" + 
                            txtPhone.Text + "')", myConnection);

    try
    {
        myCommand.ExecuteNonQuery();
        BCE.Application.AppMessage.ShowMessage("Pass!!!");
    }
    catch
    {
        BCE.Application.AppMessage.ShowMessage(myCommand.CommandText );
    }
    myConnection.Close();
}
Posted
v2
Comments
What is the error?
Namith Krishnan E 14-Oct-14 2:25am    
is data type of column 'TestIC' is varchar?

1 solution

C#
private void cmdAdd_Click(object sender, EventArgs e)
{
     String connStr= "Data Source=ACER-LAPTOP\a2006; Database=AED_MOBILE_0; Initial Catalog=db_stuRegisterPay; Integrated Security=SSPI";

    SqlConnection myConnection = new SqlConnection(connStr);
    myConnection.Open();
 
    SqlCommand myCommand = new SqlCommand("INSERT INTO TestInfo(TestIC, TestName, TestPhone) " + "VALUES('" + txtIC.Text + "','" + txtName.Text + "','" + 
                            txtPhone.Text + "')", myConnection);
 
    try
    {
        myCommand.ExecuteNonQuery();
        BCE.Application.AppMessage.ShowMessage("Pass!!!");
    }
    catch
    {
        BCE.Application.AppMessage.ShowMessage(myCommand.CommandText );
    }
    myConnection.Close();
}


if not working then explain your error.
 
Share this answer
 
Comments
Member 11146537 18-Oct-14 5:19am    
still error..

Format of the initialization string does not conform to specification starting at index 23.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900