473,385 Members | 1,821 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,385 software developers and data experts.

insert statement into sql not working correctly. something is wrong with the dataread

Expand|Select|Wrap|Line Numbers
  1. Private Sub Button_Submit_Click(sender As System.Object, e As System.EventArgs) Handles Button_Submit.Click
  2.         Submit.Submit()
  3.  
  4.         Dim Connection As New OleDbConnection(_conString)
  5.         Dim DataReader As OleDbDataReader
  6.         Dim Command As New OleDbCommand
  7.         Dim Query As String
  8.  
  9.         Connection.Open()
  10.  
  11.         Query = "INSERT INTO LOGIN(user_name, password, user_type, firstname, lastname, email, address) values ( ?,?,?,?,?,?,?)"
  12.  
  13.  
  14.         'Command.Connection = Connection
  15.         'Command.CommandText = Query
  16.  
  17.         DataReader = Command.ExecuteReader()
  18.  
  19.         Command.Parameters.AddWithValue("User_Name", TextBox_UserName.Text)
  20.         Command.Parameters.AddWithValue("Password", TextBox_Password.Text)
  21.         Command.Parameters.AddWithValue("User_Type", TextBox_Usertype.Text)
  22.         Command.Parameters.AddWithValue("FirstName", TextBox_FirstName.Text)
  23.         Command.Parameters.AddWithValue("LastName", TextBox_LastName.Text)
  24.         Command.Parameters.AddWithValue("Email", TextBox_Email.Text)
  25.         Command.Parameters.AddWithValue("Address", TextBox_Address.Text)
  26.  
  27.         'Command.ExecuteNonQuery()
  28.  
  29.         MessageBox.Show("Added Successful")
  30.  
  31.         Try
  32.         Catch ex As Exception
  33.             MessageBox.Show(ex.Message)
  34.         Finally
  35.             Connection.Close()
  36.  
  37.  
  38.         End Try
  39.     End Sub
  40.  
  41. End Class
Apr 21 '13 #1
4 1161
Rabbit
12,516 Expert Mod 8TB
You gave your parameters a name but you didn't use those names in the SQL query. You should also start your parameter names with @
Apr 21 '13 #2
Which parameters names? They all look they same to me. What do you mean?
Apr 21 '13 #3
Rabbit
12,516 Expert Mod 8TB
Line 11, you use ? to designate your variables. But then you add parameters with names on lines 19-25. The query has no idea which of those names matches up with the question marks. Just because you gave the parameter the same name as a field in the table doesn't mean the engine knows to translate that into the same location in the SQL. You need to use the parameter names in the SQL itself and you need to start your parameter names with the @ symbol.
Apr 21 '13 #4
vijay6
158 100+
Hey jsand03z, you have to use like as follows...

Replace line number 11 with the following code...

Expand|Select|Wrap|Line Numbers
  1. Query = "INSERT INTO LOGIN(user_name, password, user_type, firstname, lastname, email, address) values (@User_Name, @Password, @User_Type, @FirstName, @LastName, @Email, @Address)"

Then replace line number 19 to 25 with the following codes...

Expand|Select|Wrap|Line Numbers
  1. Command.Parameters.AddWithValue("@User_Name", TextBox_UserName.Text)
  2. Command.Parameters.AddWithValue("@Password", TextBox_Password.Text)
  3. Command.Parameters.AddWithValue("@User_Type", TextBox_Usertype.Text)
  4. Command.Parameters.AddWithValue("@FirstName", TextBox_FirstName.Text)
  5. Command.Parameters.AddWithValue("@LastName", TextBox_LastName.Text)
  6. Command.Parameters.AddWithValue("@Email", TextBox_Email.Text)
  7. Command.Parameters.AddWithValue("@Address", TextBox_Address.Text)

Check your code again you misplaced "Try" (It should be placed before line number 9 in your code).
Apr 23 '13 #5

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

Similar topics

4
by: soni29 | last post by:
hi, i have a small question regarding sql, there are two tables that i need to work with on this, one has fields like: Table1: (id, name, street, city, zip, phone, fax, etc...) about 20 more...
4
by: Curt Morrison | last post by:
I have an ASP login section on my site that is experiencing some problems. Go to the following page and create a fake account (this is a test environment, so don't worry): ...
10
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void...
2
by: eric dugal | last post by:
Hi all!! I need your help.... i'm working since 2 hours on a simple insert statement, but couldn't handle it. Here is my code : public int ExecQuery(string SqlString) {
2
by: Paul Mason | last post by:
Hi folks, The ado.net stream appears to be not working so I'm here. The following function generates the error "Operation must use an updateable query". There is no identifiable or meaningful...
1
by: glenn | last post by:
Hi folks, I am using an Access database, VB.NET and ADO.NET working with a DataGrid control. MY datagrid table has both a date_sent and a date_ans field. When I Insert a record in my SQL...
3
by: rhaazy | last post by:
Using ms sql 2000 I have 2 tables. I have a table which has information regarding a computer scan. Each record in this table has a column called MAC which is the unique ID for each Scan. The...
2
by: Good Guy | last post by:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Customers_Contact". The conflict occurred in database "BreakAway", table "dbo.Contact", column 'ContactID'. The statement has...
0
by: Billie Hartline | last post by:
I am an untrained Volunteer assisting a non-profit organization What I am attempting to do is Select the Max(ID) following an Insert into the database. Then pass the MaxID to a second page and...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.