Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Have Created an application with sql database?
but it'll give me an error saying
"
SQL
The parameterized query '(@Uname nvarchar(5),@Cus_Name nvarchar(5),@Cus_Cntat bigint,@Sub' expects the parameter '@TktType', which was not supplied.
"

my database is like this

Id = int(automatically generated) not allow nulls
Uname = Varchar(max)
Cust_Name = Varchar(max)
Cust_Cntact = Varchar(max)
Submit_Date = date
Req_Date = date
More_Details = Varchar(max)
Ticket_Type = Varchar(max)
Pax_No = int
First_Stat = Varchar(max)
Sec_Stat = Varchar(max)
Third_Stat = Varchar(max)

all other allows null other than id.

and i set the data format as well........

C#
using (SqlCommand command = new SqlCommand("INSERT INTO Enquiry (Uname,Cust_Name,Cust_Cntact,Submit_Date,Req_Date,More_Details,Ticket_Type,Pax_No,First_Stat,Sec_Status,Third_Status) VALUES (@Uname,@Cust_Name,@Cust_Cntact, @Submit_Date, @Req_Date, @More_Details, @Ticket_Type, @Pax_No, @First_Stat, @Sec_Status, @Third_Status)", con))
               {
                  command.Parameters.AddWithValue("@Uname", ClassEnq.Uname);
                    command.Parameters.AddWithValue("@Cust_Name", Cus_Name1);
                    command.Parameters.AddWithValue("@Cust_Cntact", Convert.ToInt64(Cus_Contact.Text));
                    command.Parameters.AddWithValue("@Submit_Date", Submit.Value.Date);
                    command.Parameters.AddWithValue("@Req_Date", Required.Value.Date);
                    command.Parameters.AddWithValue("@More_Details", More_Info.Text);
                    command.Parameters.AddWithValue("@Ticket_Type", Tkt_Type.SelectedValue);
                    command.Parameters.AddWithValue("@Pax_No", Convert.ToInt32(Pax_Count.SelectedValue));
                    command.Parameters.AddWithValue("@First_Stat", Stat_One.SelectedValue);
                    command.Parameters.AddWithValue("@Sec_Status", StatTwo.Text);
                    command.Parameters.AddWithValue("@Third_Status", Stat_Three.Text);


                   command.ExecuteNonQuery();
                   con.Close();

                   MessageBox.Show("Record inserted. Please check your table data. :)");
               }


i think there is no issue with parameters because all are matched.
Posted
Updated 9-Jan-15 20:51pm
v2

The error message is very, very explicit:
The parameterized query '(@Uname nvarchar(5),@Cus_Name nvarchar(5),@Cus_Cntat bigint,@Sub' expects the parameter '@TktType', which was not supplied.
and your code does not include any parameter called @TktType except in the INSERT statement.
C#
using (SqlCommand command = new SqlCommand("INSERT INTO Enquiry (Uname,...,Sec_Status_Third_Status) VALUES (@Uname..., @More_Info, @TktType, @Pax_No,..., @ThirdStat)", con))

Without the matching
C#
command.Parameters.AddWithValue("@TktType", ...
 
Share this answer
 
Try this:
C#
if (Tkt_Type.SelectedValue != null)
{
      command.Parameters.AddWithValue("@TktType", Tkt_Type.SelectedValue);
}
     else
{
      command.Parameters.AddWithValue("@TktType", DBNull.Value );
}
 
Share this answer
 

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