Skip to content

Other problem

Kaneshapillai Sathulan

Kaneshapillai Sathulan

Asked Apr 23, 2013, 12:55 AM EDT1 answer
Share
LinkedInX
hi dude do not mistake me.... i had get  other problem 

C#
            Cone = new SqlConnection(connstring);
           Cone.Open();
                Come=new SqlCommand("insert into cheque values("+chno.Text+","+amo.Text+","+Date.Text+","+Towhom.Text+","+Purpo.Text+"')",Cone);
                try
                {
                    Come.ExecuteNonQuery();
                    MessageBox.Show("Saved............");
                }
                catch (Exception)
                {
                    MessageBox.Show("not saved......");
                }
                finally
                {
                    Cone.Close();
                }


if i check i have get catch details only what about that problem........
chno.Text=int
amo.Text=money
Date.Text=date
Towhom.Text=nvarchar(max)
Purpo.Text=nvarchar(max)

                please help me dude.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Vishal Gilbile
    0
    Hi Ganesh,
                      Check your DB Table Structure and accordingly pass values in that specific format. For instance what i can make out your cheque no column would be an integer amount column let's say is money or float, Date column is datetime or varchar etc.
    so while passing values I'll passing in the same format. And also the better approach for writing queries would be like the following.

    SqlCommand cmd=new SqlCommand("insert into cheque values(@chkno,@amt,@date,@towhom,@purpo)",con);
    cmd.Parameters.AddWithValue("@chkno",Convert.ToInt32(
    chno.Text));
    cmd.Parameters.AddWithValue("@amt",amo.Text);
    cmd.Parameters.AddWithValue("@date",Convert.ToDateTime(Date.Text));
    cmd.Parameters.AddWithValue("@towhom",Convert.ToInt32(Towhom.Text));
    cmd.Parameters.AddWithValue("@purpo",Convert.ToInt32(Purpo.Text));
    con.Open();//Connection Object.
    int rows=cmd.ExecuteNonQuery();
    con.Close();//close the Connection

    Also for your guidance try to use naming conventions for instance for TextBox control provide and ID like txtChequeNo for label lblName

    which makes your program easily understandable to the reader.
    0