473,396 Members | 2,087 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,396 software developers and data experts.

Whats wrong with this code for database insert?

Public Class Customerdetails
Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
updatecustomerdatabase("Insert INTO Customer (FirstName), VALUES cstr(txtcustomername.text)")

End Sub
Sub updatecustomerdatabase(ByVal sqlStr As String)
Dim newcustomer As New DataTable
Dim connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source = maindatabase.mdb"
Dim dataAdaptor4 As New OleDb.OleDbDataAdapter(sqlStr, connStr)
dataAdaptor4.Fill(newcustomer)
dataAdaptor4.Dispose()

End Sub
End Class
Oct 12 '06 #1
1 1209
Expand|Select|Wrap|Line Numbers
  1. Public Class Customerdetails
  2.     Inherits System.Windows.Forms.Form
  3.  
  4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  5.         updatecustomerdatabase("Insert INTO Customer  (FirstName), VALUES cstr(txtcustomername.text)")
  6.  
  7.     End Sub
  8.     Sub updatecustomerdatabase(ByVal sqlStr As String)
  9.         Dim newcustomer As New DataTable
  10.         Dim connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  11.                                 "Data Source = maindatabase.mdb"
  12.         Dim dataAdaptor4 As New OleDb.OleDbDataAdapter(sqlStr, connStr)
  13.         dataAdaptor4.Fill(newcustomer)
  14.         dataAdaptor4.Dispose()
  15.  
  16.     End Sub
  17. End Class
I am not sure
But it could be this

"Insert INTO Customer (FirstName), VALUES cstr(txtcustomername.text)"

is not a proper SQL query.
is txtcustomername a textbox?

then the row
updatecustomerdatabase("Insert INTO Customer (FirstName), VALUES cstr(txtcustomername.text)")

should be change to
updatecustomerdatabase("Insert INTO Customer (FirstName), VALUES '" + cstr(txtcustomername.text) + "'")

notice the '
hope this was a help.
Oct 12 '06 #2

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

Similar topics

9
by: cricketunes | last post by:
Hi folks, this one's had me stumped! $conn=ora_logon("cricketunes@pickles","j8j3kf"); if ($conn != TRUE) die("Unable to connect to oracle, exiting...\n"); $cursor = ora_open($conn); if...
5
by: Mike M | last post by:
Hi all, I ahve the following SQL string but when i try to response.Write it there is a error where the ',' should be between "city" and "County" SQL = "INSERT * INTO customers (Company_Name,...
2
by: Jim | last post by:
Im getting way too many rows retured..what its trying to do is insert a 0 for revenue for months 7 - 12 (aka July through December) for each of these cost centers for each payor type..Im getting a...
3
by: Chris Geerdink | last post by:
combo with PHP. what is wrong with the Javascript? else { include("mysql.php"); $query1 = mysql_query("INSERT INTO gbook (naam, email, text) VALUES ('".$_POST."', '".$_POST."',...
4
by: asdf | last post by:
Hello! Can someone tell me whats wrong with this piece of code: Option Compare Database Option Explicit Sub retrieve() Dim rst As ADODB.Recordset Dim i As Integer
2
by: Jack | last post by:
It appears that RecordsAffected reports the wrong value when a Null integer or date value is inserted using empty quotes. The insert works fine, but RecordsAffected reports 0 instead of 1. Here...
5
by: Alexandre Martins | last post by:
Provider=Microsoft.Jet.OLEDB.4.0;UserId=Admin;Password=teste;Data Source=C:\Inetpub\wwwroot\inktoner\dados\db_inktoner.mdb;Persist Security Info=True I can't connect in my database ! whats...
3
by: snowweb | last post by:
I'm creating my first web application in PHP/MySQL, however, when I go to view the database contents, the data has been stored in the wrong columns. I've gone through my insertion code with a fine...
7
by: studentofknowledge | last post by:
im trying to add form data in to my local sql 2005 database but having a lot of trouble. I have searched the web but im coming across misleading information time and time again. below is my code ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.