473,413 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

saving the data in sqlserver parameter error showing

I have an application with general customer detail.

It has TextBox and radio button.

First I have used if statement then code but on first step is working fine then error is showing. I'm not getting what I'm missing can any body guide me .......

Expand|Select|Wrap|Line Numbers
  1.  try
  2.             {
  3.                 if (textBox1.Text == "")
  4.                 {
  5.                     MessageBox.Show("Please Enter The First Name");
  6.                     //textBox1.Focus();
  7.                 }
  8.                 else if (radioButton1.Checked == false && radioButton2.Checked == false)
  9.                 {
  10.                     MessageBox.Show("Please Select  The Gender ");
  11.                     //radioButton1.Focus();
  12.                 }
  13.                 else if (checkBox1.Checked == false && checkBox2.Checked == false)
  14.                 {
  15.                     MessageBox.Show("Please Enter Your Phone Or Mobile Number");
  16.                     //checkBox1.Focus();
  17.                 }
  18.                 else if (textBox6.Text == "")
  19.                 {
  20.                     MessageBox.Show("Please Enter Your Email Id");
  21.                     //textBox6.Focus();
  22.                 }
  23.                 else if (radioButton3.Checked == false && radioButton4.Checked == false && radioButton5.Checked == false && radioButton6.Checked == false)
  24.                 {
  25.                     MessageBox.Show("Please Grade Us According To Our Service");
  26.                     //radioButton3.Focus();
  27.                 }
  28.  
  29.             }
  30.             catch (Exception ex)
  31.             {
  32.                 //MessageBox.Show("Please Fill The Required Blanks");
  33.  
  34.             }
  35.  
  36.                 con.Open();
  37.                 SqlCommand cmd = new SqlCommand();
  38.                 cmd.Connection = con;
  39.                 cmd.CommandType = CommandType.StoredProcedure;
  40.                 cmd.CommandText = "insertpro";
  41.                 cmd.Parameters.AddWithValue("@firstname", textBox1.Text);
  42.                 cmd.Parameters.AddWithValue("@lastname", textBox2.Text);
  43.                 if (radioButton1.Checked == true)
  44.                 {
  45.                     cmd.Parameters.AddWithValue("@gender", radioButton1.Text);
  46.                 }
  47.                 else if (radioButton2.Checked == true)
  48.                 {
  49.                     cmd.Parameters.AddWithValue("@gender", radioButton2.Text);
  50.                 }
  51.                 //else if (radioButton1.Checked == false && radioButton2.Checked ==false )
  52.                 //{
  53.                 //    cmd.Parameters.AddWithValue("@gender","");
  54.                 //}
  55.                 cmd.Parameters.AddWithValue("@age", comboBox1.Text);
  56.                 cmd.Parameters.AddWithValue("@company", textBox3.Text);
  57.                 cmd.Parameters.AddWithValue("@profession", textBox10.Text);
  58.                 cmd.Parameters.AddWithValue("@adress", textBox7.Text);
  59.                 cmd.Parameters.AddWithValue("@city", textBox8.Text);
  60.                 cmd.Parameters.AddWithValue("@date", DateTime.Today.TimeOfDay);
  61.  
  62.  
  63.                 SqlCommand cmd1 = new SqlCommand();
  64.                 cmd1.Connection = con;
  65.                 cmd1.CommandType = CommandType.StoredProcedure;
  66.                 cmd1.CommandText = "insertfeed";
  67.                 cmd1.Parameters.AddWithValue("@contactnoph", textBox4.Text);
  68.                 cmd1.Parameters.AddWithValue("@emailadress", textBox6.Text);
  69.                 if (radioButton3.Checked == true)
  70.                 {
  71.                     cmd1.Parameters.AddWithValue("@remark", radioButton3.Text);
  72.                     cmd1.Parameters.AddWithValue("@remarkid", 0);
  73.                 }
  74.                 else if (radioButton4.Checked == true)
  75.                 {
  76.                     cmd1.Parameters.AddWithValue("@remark", radioButton4.Text);
  77.                     cmd1.Parameters.AddWithValue("@remarkid", 1);
  78.                 }
  79.                 else if (radioButton5.Checked == true)
  80.                 {
  81.                     cmd1.Parameters.AddWithValue("@remark", radioButton5.Text);
  82.                     cmd1.Parameters.AddWithValue("@remarkid", 2);
  83.                 }
  84.                 else if (radioButton6.Checked == true)
  85.                 {
  86.                     cmd1.Parameters.AddWithValue("@remark", radioButton6.Text);
  87.                     cmd1.Parameters.AddWithValue("@remarkid", 3);
  88.                 }
  89.                 else if (radioButton3.Checked == false && radioButton4.Checked == false && radioButton5.Checked == false && radioButton6.Checked == false)
  90.                 {
  91.                     cmd1.Parameters.AddWithValue("@remark", "");
  92.                     cmd1.Parameters.AddWithValue("@remarkid", "");
  93.                 }
  94.                 if (comboBox2.SelectedIndex == 1)
  95.                 {
  96.                     cmd1.Parameters.AddWithValue("@sugession", textBox9.Text);
  97.                     cmd1.Parameters.AddWithValue("@sugid", 1);
  98.                 }
  99.                 else if (comboBox2.SelectedIndex == 2)
  100.                 {
  101.                     cmd1.Parameters.AddWithValue("@sugession", textBox9.Text);
  102.                     cmd1.Parameters.AddWithValue("@sugid", 2);
  103.                 }
  104.                 else if (comboBox2.SelectedIndex == 0)
  105.                 {
  106.                     cmd1.Parameters.AddWithValue("@sugession", textBox9.Text);
  107.                     cmd1.Parameters.AddWithValue("@sugid", 0);
  108.                 }
  109.                 cmd1.Parameters.AddWithValue("@firstname", textBox1.Text);
  110.                 cmd1.Parameters.AddWithValue("@contactnomob", textBox5.Text);
  111.                 cmd.ExecuteNonQuery();
  112.                 cmd1.ExecuteNonQuery();
  113.                 con.Close();
  114.                 MessageBox.Show("Thanks For Your Feed Back.");
  115.                 textBox1.Text = "";
  116.                 textBox2.Text = "";
  117.                 textBox3.Text = "";
  118.                 textBox4.Text = "";
  119.                 textBox5.Text = "";
  120.                 textBox6.Text = "";
  121.                 textBox7.Text = "";
  122.                 textBox8.Text = "";
  123.                 textBox9.Text = "";
  124.                 textBox10.Text = "";
  125.                 comboBox1.SelectedIndex = 0;
  126.                 comboBox2.SelectedIndex = 0;
  127.                 radioButton1.Checked = false;
  128.                 radioButton2.Checked = false;
  129.                 radioButton3.Checked = false;
  130.                 radioButton4.Checked = false;
  131.                 radioButton5.Checked = false;
  132.                 radioButton6.Checked = false;
  133.                 checkBox1.Checked = false;
  134.                 checkBox2.Checked = false;
  135.  
  136.             }
  137.  
Jun 1 '13 #1
5 1556
Rabbit
12,516 Expert Mod 8TB
I can not understand what you are asking at all.
Jun 2 '13 #2
vijay6
158 100+
Hey Syed Hadi, where is the insert query in your code? (The insert query you wrote was wrong.)

You've to use like this...
Expand|Select|Wrap|Line Numbers
  1. SqlCommand myCommand = new SqlCommand("INSERT INTO TableName (Column1, Column2, ..., ColumnN) VALUES (@Param1, @Param2, ..., @ParamN)", myConnection);
  2. myCommand.Parameters.AddWithValue("@Param1", variable1);
  3. myCommand.Parameters.AddWithValue("@Param2", variable2);
  4. ...
  5. myCommand.Parameters.AddWithValue("@ParamN", variableN);
  6. myCommand.Open();
  7. myCommand.ExecuteNonQuery();
  8. myCommand.Close();
Jun 2 '13 #3
@vijay6 i m using procedure for inserting the values
Jun 8 '13 #4
vijay6
158 100+
@vijay6 i m using procedure for inserting the values
Okay.

Hey Syed Hadi, the mistake i noticed from your code is, codes from line number 36 to line number 134 should be placed inside the else statement after line number 27 in your code.
Jun 8 '13 #5
Yeah I did that.
Its right.
Thanks.
Jun 9 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Laurel | last post by:
this is driving me crazy. i need to use a form control as a criteria in a select query, and the control's value is set depending upon what a user selects in an option group on the form. the query...
3
by: Martin Lacoste | last post by:
Is there some issue with using too many left/right/mid/len functions in queries? Depending on the usage, they work fine, but... then there's here: SELECT Master_CAO.Incipit,...
0
by: news.paradise.net.nz | last post by:
I have been developing access databases for over 5 years. I have a large database and I have struck this problem with it before but can find nothing in help or online. Access 2000 I have a query...
0
by: Manuel Arroba | last post by:
asp.net oledb command parameter error calling an as400 program Hi... I have an as400 program that I can call it directly and it works: variable= "xxxx" sql = "CALL METSIGOP.SIGOPRC ('" +...
1
by: pmclinn | last post by:
I have a formated a structure as follows: <Serializable()>public structure stcOutPut private data as string private visi as string end structure Instances of this strucuture are stored in an...
2
by: Captain Gadget | last post by:
I cannot update a child table to the main using the wizard criteria column with out errors occuring. I'm using ACCESS database 1 main table, 1 child. The 2 tables are related, no problem. I...
1
by: IMRAN | last post by:
I have created a component which parses some flat files and stores in Sql database. Now I want to move that COM object to database server. Now the scenario will be like this : 1) ASP page...
1
by: Damon | last post by:
I've distilled this down into the simplest possible code fragment and this still doesn't make any sense. I'm trying to run a select query on an access database, and the query has NO parameters. ...
1
by: Magnus | last post by:
I'm testing walkthrough saving data to a Database (Multiple Tables). http://msdn2.microsoft.com/en-us/library/4esb49b4(VS.80).aspx In the famous Customer/Order example, I'm getting referential...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.