hello sir
i am making project on vb.net language..and project is on hospital management..its major project..and too many fields are present in its data base..i was connecting data base in forms but there is coming error..SIR PLEASE SORT OUT ERROR FROM MY COADING..what can i do to solve this error please give me sugession or if you can send me coading for adding information from form.than i will be thankfull to u..i have written all fields which has present in my database please help me..
error coming - too many parameters.
I HAVE MADE DATABASE ON MS ACCESS
SOURCE CODE - -
Dim cmd As New OleDbCommand("insert into table1 values(@date,@firstname,@middlename,@lastname,@maritalstatus,@sex,@feetype,
-
@mothersName,@fathersname,@dd,@mm,@yy,@age,@residentialaddress,@city,@state,@country,@pincode,@religion,@bloodgroup,@telephoneno, @mobile,@pager,@email)", con)
-
-
cmd.parameters.addwithvalue("@date", TextBox2.Text)
-
cmd.Parameters.AddWithValue("@firstname", TextBox14.Text)
-
cmd.Parameters.AddWithValue("@middlename", TextBox4.Text)
-
cmd.Parameters.AddWithValue("@lastname", TextBox5.Text)
-
cmd.Parameters.AddWithValue("@maritalstatus", ComboBox1.Text)
-
cmd.Parameters.AddWithValue("@sex", ComboBox2.Text)
-
cmd.Parameters.AddWithValue("@feetype", ComboBox3.Text)
-
cmd.Parameters.AddWithValue("@mothersname", TextBox6.Text)
-
cmd.Parameters.AddWithValue("@fathersname", TextBox7.Text)
-
cmd.Parameters.AddWithValue("@dd", ComboBox4.Text)
-
cmd.Parameters.AddWithValue("@mm", ComboBox5.Text)
-
cmd.Parameters.AddWithValue("@yy", ComboBox6.Text)
-
cmd.Parameters.AddWithValue("@age", TextBox8.Text)
-
cmd.Parameters.AddWithValue("@residentialaddress", TextBox9.Text)
-
cmd.Parameters.AddWithValue("@city", ComboBox7.Text)
-
cmd.Parameters.AddWithValue("@state", ComboBox8.Text)
-
cmd.Parameters.AddWithValue("@country", ComboBox9.Text)
-
cmd.Parameters.AddWithValue("@pincode", TextBox3.Text)
-
cmd.Parameters.AddWithValue("@religion", ComboBox10.Text)
-
cmd.Parameters.AddWithValue("@bloodgroup", ComboBox11.Text)
-
cmd.Parameters.AddWithValue("@telephoneno", TextBox11.Text)
-
cmd.Parameters.AddWithValue("@mobile", TextBox10.Text)
-
cmd.Parameters.AddWithValue("@pager", TextBox12.Text)
-
cmd.Parameters.AddWithValue("@email", TextBox13.Text)
-
con.Open()
-
cmd.ExecuteNonQuery()
-
con.Close()
-
MsgBox("record added")
-
-
End Sub
14 3258
sir i am making project on hospital management..the language is vb.net..i have tried to do databese connecting but there is coming errors..and the error is coming just because of too many parameters..so many fields are present in my database that is why it is not connecting..i am sendimg u fields i request to u if u can send me coading for adding information of form i will be thankfull to u please help me..
fields is -
date
firstname
middlename
lastname, maritalstatus,sex,feetype,mothersName,fathersname, dd,mm,yy,age,residentialaddress,city,state,country ,pincode,religion,bloodgroup,telephoneno, mobile,pager,email
its form's field name..and when we enter information in it..information should be save in database..so please send me coading of it.i have made database on ms access..u can see my coading which i have done on project..but its not working.. -
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
-
Dim cmd As New OleDbCommand("insert into table1 values(@date,@firstname,@middlename,@lastname,@maritalstatus,@sex,@feetype,@mothersName,@fathersname,@dd,@mm,@yy,@age,@residentialaddress,@city,@state,@country,@pincode,@religion,@bloodgroup,@telephoneno, @mobile,@pager,@email)", con)
-
cmd.Parameters.AddWithValue("@date", TextBox2.Text)
-
cmd.Parameters.AddWithValue("@firstname", TextBox14.Text)
-
cmd.Parameters.AddWithValue("@middlename", TextBox4.Text)
-
cmd.Parameters.AddWithValue("@lastname", TextBox5.Text)
-
cmd.Parameters.AddWithValue("@maritalstatus", ComboBox1.Text)
-
cmd.Parameters.AddWithValue("@sex", ComboBox2.Text)
-
cmd.Parameters.AddWithValue("@feetype", ComboBox3.Text)
-
cmd.Parameters.AddWithValue("@mothersname", TextBox6.Text)
-
cmd.Parameters.AddWithValue("@fathersname", TextBox7.Text)
-
cmd.Parameters.AddWithValue("@dd", ComboBox4.Text)
-
cmd.Parameters.AddWithValue("@mm", ComboBox5.Text)
-
cmd.Parameters.AddWithValue("@yy", ComboBox6.Text)
-
cmd.Parameters.AddWithValue("@age", TextBox8.Text)
-
cmd.Parameters.AddWithValue("@residentialaddress", TextBox9.Text)
-
cmd.Parameters.AddWithValue("@city", ComboBox7.Text)
-
cmd.Parameters.AddWithValue("@state", ComboBox8.Text)
-
cmd.Parameters.AddWithValue("@country", ComboBox9.Text)
-
cmd.Parameters.AddWithValue("@pincode", TextBox3.Text)
-
cmd.Parameters.AddWithValue("@religion", ComboBox10.Text)
-
cmd.Parameters.AddWithValue("@bloodgroup", ComboBox11.Text)
-
cmd.Parameters.AddWithValue("@telephoneno", TextBox11.Text)
-
cmd.Parameters.AddWithValue("@mobile", TextBox10.Text)
-
cmd.Parameters.AddWithValue("@pager", TextBox12.Text)
-
cmd.Parameters.AddWithValue("@email", TextBox13.Text)
-
con.Open()
-
cmd.ExecuteNonQuery()
-
con.Close()
-
MsgBox("record added")
-
-
End Sub
thanking u
Data integrity is probably the issue. Make sure the values typed in the textboxes are allowed for the underlying data fields datatype. For example, if it is expecting a number, textboxes all return string values and it will error out.
Also, I would get rid of command objects in this case. You just dont need them for what you are doing.
Create a single INSERT statement like you did but remove the "@" place holders and put actual values.
For example:
INSERT INTO MyTable (Field1, Field2, Field3)
VALUES ('Value of field1', 'Value of field2', 'Value of field 3')
Also, I would get rid of command objects in this case. You just dont need them for what you are doing.
I dunno, using a command object like that is safer. It forces correct datatypes and helps prevent against sql injection.
As for the problem, I don't think that is a valid SQL INSERT statement?
I dunno, using a command object like that is safer. It forces correct datatypes and helps prevent against sql injection.
As for the problem, I don't think that is a valid SQL INSERT statement?
You are right. In this case, it's a toss up between letting the code handle exceptions or, what I like to do, check the data integrity before sending it to the db.
You are right. In this case, it's a toss up between letting the code handle exceptions or, what I like to do, check the data integrity before sending it to the db.
The problems are:
a). In your SQL statement you don't specify the fields to insert into - consequently you are required to enter all fields for the table you're inserting into. This means that if extra fields are added in your database, your query will then crash, which is what I suspect is happening to you. Try the following format: - Dim sSql As String = "Insert Into MyTable(Field1, Field2, Field3) Values(@Data1, @Data2, @Data3)"
-
Dim oCmd As New SqlCommand(sSQL, oCon)
b). Your SqlParameter instances don't need the @ symbol when you're creating your parameter object: - oCmd.Parameters.AddWithValue("Data1", TextBox1.Text)
-
oCmd.Parameters.AddWithValue("Data2", TextBox2.Text)
-
oCmd.Parameters.AddWithValue("Data3", TextBox3.Text)
Notice how in my SQL statement I specify the placeholders using the @ symbol, but when I create my SqlParameter instances, I don't use the @ symbol.
If you correct both of these issues in your code, it should fix your problem.
Problem is not with number of parameters.
Which line of code is creating the error ?
hello sir
i want to know,after inserting the data in the textbox, how can we add that data in the database with the click of a button?
sir i have written code for this work please correct my coding..
error coming - "Data type mismatch in criteria expression"
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
cmd.Parameters.AddWithValue("@date", TextBox2.Text)
cmd.Parameters.AddWithValue("@uhid.textbox1.text)
cmd.Parameters.AddWithValue("@first name,TextBox14.Text)
cmd.Parameters.AddWithValue("@middle name",TextBox4.Text)
cmd.Parameters.AddWithValue( "@last name",TextBox5.Text)
cmd.Parameters.AddWithValue("@marital status",ComboBox1.Text)
cmd.Parameters.AddWithValue("@sex",ComboBox2.Text)
cmd.Parameters.AddWithValue("@fee type",ComboBox3.Text)
cmd.Parameters.AddWithValue("@mother's Name",TextBox6.Text)
cmd.Parameters.AddWithValue("@father's name",TextBox7.Text)
cmd.Parameters.AddWithValue("@dd",ComboBox4.Text)
cmd.Parameters.AddWithValue("@mm",ComboBox5.Text)
cmd.Parameters.AddWithValue("@yy",ComboBox6.Text)
cmd.Parameters.AddWithValue("@age",TextBox8.Text)
cmd.Parameters.AddWithValue("@residential address"TextBox9.Text)
cmd.Parameters.AddWithValue("@city"combobox7.text)
cmd.Parameters.AddWithValue("@state",combobox8.tex t)
cmd.Parameters.AddWithValue ("@country",combobox9.text)
cmd.Parameters.AddWithValue("@pincode""TextBox3.Te xt)
cmd.Parameters.AddWithValue("@region",combox10.tex t)
cmd.Parameters.AddWithValue ("@blood group",combobox11.text)
cmd.Parameters.AddWithValue("@telephone no",textbox11.text)
cmd.Parameters.AddWithValue ("@mobile",textbox10.text)
cmd.Parameters.AddWithValue("@pager",TextBox12.Tex t)
cmd.Parameters.AddWithValue("@email",textbox13.tex t)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
MsgBox("record added")
End Sub
hello sir
i want to know after inserting data in the textbox than how can we add this data to the database.with the help of click of button.
sir i have written coad for this work please check the coding
error coming - Data type mismatch in criteria expression
please solve my problem
source code - -
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
-
-
cmd.Parameters.AddWithValue("@date", TextBox2.Text)
-
cmd.Parameters.AddWithValue("@uhid.textbox1.text)
-
cmd.Parameters.AddWithValue("@first name,TextBox14.Text)
-
cmd.Parameters.AddWithValue("@middle name",TextBox4.Text)
-
cmd.Parameters.AddWithValue( "@last name",TextBox5.Text)
-
cmd.Parameters.AddWithValue("@marital status",ComboBox1.Text)
-
cmd.Parameters.AddWithValue("@sex",ComboBox2.Text)
-
cmd.Parameters.AddWithValue("@fee type",ComboBox3.Text)
-
cmd.Parameters.AddWithValue("@mother's Name",TextBox6.Text)
-
cmd.Parameters.AddWithValue("@father's name",TextBox7.Text)
-
cmd.Parameters.AddWithValue("@dd",ComboBox4.Text)
-
cmd.Parameters.AddWithValue("@mm",ComboBox5.Text)
-
cmd.Parameters.AddWithValue("@yy",ComboBox6.Text)
-
cmd.Parameters.AddWithValue("@age",TextBox8.Text)
-
cmd.Parameters.AddWithValue("@residential address"TextBox9.Text)
-
cmd.Parameters.AddWithValue("@city"combobox7.text)
-
cmd.Parameters.AddWithValue("@state",combobox8.text)
-
cmd.Parameters.AddWithValue ("@country",combobox9.text)
-
cmd.Parameters.AddWithValue("@pincode""TextBox3.Text)
-
cmd.Parameters.AddWithValue("@region",combox10.text)
-
cmd.Parameters.AddWithValue ("@blood group",combobox11.text)
-
cmd.Parameters.AddWithValue("@telephone no",textbox11.text)
-
cmd.Parameters.AddWithValue ("@mobile",textbox10.text)
-
cmd.Parameters.AddWithValue("@pager",TextBox12.Text)
-
cmd.Parameters.AddWithValue("@email",textbox13.text)
-
con.Open()
-
cmd.ExecuteNonQuery()
-
con.Close()
-
MsgBox("record added")
-
-
End Sub
hello sir
i want to know after inserting data in the textbox than how can we add this data to the database.with the help of click of button.
i m making project in visual studio 2005
backend - ms access
sir i have written coad for this work please check the coding
error coming - Data type mismatch in criteria expression
please solve my problem
source code - -
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
-
-
cmd.Parameters.AddWithValue("@date", TextBox2.Text)
-
cmd.Parameters.AddWithValue("@uhid.textbox1.text)
-
cmd.Parameters.AddWithValue("@first name,TextBox14.Text)
-
cmd.Parameters.AddWithValue("@middle name",TextBox4.Text)
-
cmd.Parameters.AddWithValue( "@last name",TextBox5.Text)
-
cmd.Parameters.AddWithValue("@marital status",ComboBox1.Text)
-
cmd.Parameters.AddWithValue("@sex",ComboBox2.Text)
-
cmd.Parameters.AddWithValue("@fee type",ComboBox3.Text)
-
cmd.Parameters.AddWithValue("@mother's Name",TextBox6.Text)
-
cmd.Parameters.AddWithValue("@father's name",TextBox7.Text)
-
cmd.Parameters.AddWithValue("@dd",ComboBox4.Text)
-
cmd.Parameters.AddWithValue("@mm",ComboBox5.Text)
-
cmd.Parameters.AddWithValue("@yy",ComboBox6.Text)
-
cmd.Parameters.AddWithValue("@age",TextBox8.Text)
-
cmd.Parameters.AddWithValue("@residential address"TextBox9.Text)
-
cmd.Parameters.AddWithValue("@city"combobox7.text)
-
cmd.Parameters.AddWithValue("@state",combobox8.text)
-
cmd.Parameters.AddWithValue ("@country",combobox9.text)
-
cmd.Parameters.AddWithValue("@pincode""TextBox3.Text)
-
cmd.Parameters.AddWithValue("@region",combox10.text)
-
cmd.Parameters.AddWithValue ("@blood group",combobox11.text)
-
cmd.Parameters.AddWithValue("@telephone no",textbox11.text)
-
cmd.Parameters.AddWithValue ("@mobile",textbox10.text)
-
cmd.Parameters.AddWithValue("@pager",TextBox12.Text)
-
cmd.Parameters.AddWithValue("@email",textbox13.text)
-
con.Open()
-
cmd.ExecuteNonQuery()
-
con.Close()
-
MsgBox("record added")
-
-
End Sub
The type you pass to your stored procedure must match the type for the parameter. You are getting this error because you are passing a string when your proc expects a different type. You will need to Convert the text from your textboxes to match the type that your parameter expects. - ("@Parameter1", Convert.ToInt32(TextBox1.Text);
Nathan
Please do not post duplicate questions. This violates the posting guidelines.
Nathan
Just match the type with your database scheme ...
Please do not post duplicate questions. This violates the posting guidelines.
Nathan
Please read the Posting guidelines. Specifically the section on Do not double post your question.
I have merged all of your duplicate threads into this one and I am closing this thread.
You can see the solution to your problem in your other thread that has the answers. That is where you can continue to receive help on your problem.
-Moderator Frinny
I split off your question from the articles section (do not post questions there) and merged a number of your similar threads. Please don't post the same question over and over again.
MODERATOR
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
reply
views
Thread by Jonathan Moss |
last post: by
|
2 posts
views
Thread by Alistair |
last post: by
|
13 posts
views
Thread by perplexed |
last post: by
|
14 posts
views
Thread by Ian Rastall |
last post: by
|
7 posts
views
Thread by Jared Evans |
last post: by
|
1 post
views
Thread by Andre Ranieri |
last post: by
|
2 posts
views
Thread by altergothen |
last post: by
| |
6 posts
views
Thread by Bunty |
last post: by
| | | | | | | | | | |