Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
   String query = "insert into Accounts(Account_No,Account_title,Entry_Date,Initial_Deposite,Account_type,Account_Nature,Postal_Code,District,City,Name,Father_name,Husband_name,Occupation,Mobile,Gender,Marital_status)values(@Account_No,@Account_title,@Entry_Date,@Initial_Deposite,@Account_type,@Account_Nature,@Postal_Code,@District,@city,@Name,@Father_name,@Husband_name,@Occupation,@Mobile,@Gender,@Marital_status)";
                        SqlCommand cmd = new SqlCommand(query, cn);
                        cmd.Prepare();
                        cmd.Parameters.AddWithValue("@Account_No", txtac1.Text + "-" + txtac2.Text);
 cmd.Parameters.AddWithValue("@Account_title", txtaccounttitle.Text);
cmd.Parameters.AddWithValue("@Entry_Date", dateTimePicker1.Value.Date);
cmd.Parameters.AddWithValue("@Initial_Deposite", txtinitial.Text + "/-");
cmd.Parameters.AddWithValue("@Account_type", txttype.Text);
cmd.Parameters.AddWithValue("@Account_Nature", cboaccountnature.SelectedItem);
cmd.Parameters.AddWithValue("@Postal_code", txtpostal.Text);
cmd.Parameters.AddWithValue("@District", cbodistrict.SelectedItem);
cmd.Parameters.AddWithValue("@City", cbocity.SelectedItem);
cmd.Parameters.AddWithValue("@Name", txtname1.Text);
cmd.Parameters.AddWithValue("@Father_name", txtfather1.Text);
cmd.Parameters.AddWithValue("@Husband_name", txthusband1.Text);
cmd.Parameters.AddWithValue("@Occupation", txtoccupation1.Text);
cmd.Parameters.AddWithValue("@Mobile", cbocode.Text + "-" + txtmobile1.Text);
cmd.Parameters.AddWithValue("@Marital_status", cbomarital.Text);
if (rdomale.Checked == true)
 cmd.Parameters.AddWithValue("@Gender", rdomale.Text);
 else if (rdofemale.Checked == true)
cmd.Parameters.AddWithValue("@Gender", rdofemale.Text);
cmd.ExecuteNonQuery();
                        MessageBox.Show("Record Stored Successfully", "Success Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                          }
Posted
Comments
Nandakishore G N 27-Nov-12 4:21am    
have you written any triggers or any transactions..check it out in its related tables and queries.
zeshanazam 27-Nov-12 4:23am    
query was working successfully, but from last two days, same error exists...
Nandakishore G N 27-Nov-12 4:30am    
ok..it was working fine..few days ago..but now verify..are there any triggers and if u are storing in multiple tables on this insert..it occurs..better check it out all the related table and queries..because, we cannot view your system right?..
zeshanazam 27-Nov-12 4:42am    
i am storing in single tables on this insert.
zeshanazam 27-Nov-12 5:25am    
there no triggers.

Paste the following function inside the code. and call this function wherever you are using string or text. for eg textbox1.text.NullToString().

C#
public static string NullToString(this object obj)
        {
            return (obj.IsNull() ? string.Empty : Convert.ToString(obj));
        }
 
Share this answer
 
I think problem persist with your radio button. i think both radio button not checked and column not allow null.
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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