SQL insert problem

johnuk4

Active member
Joined
Feb 18, 2006
Messages
25
Programming Experience
Beginner
A problem i am having is that i need to enter a value for the Hardware_Problem_Id which is set to autonumber in the access database. Am i right in thinking that you use null?
Also could anyone tell me how you would include a time and date stamp in the string, here is my attempt so far

SQLStr4 = "INSERT INTO Hardware_Problems (Hardware_Problem_Id, Hardware_Id, Date_Reported, Time_Reported, Staff_Reported, Problem_Description, Location, Resolve_Flag) VALUES (NULL, @Hardware_Id, '10/02/2006', '10:21', @Staff_Reported, @Problem_Description, @Location, 'Yes')"

Dim sqlCommand AsNew System.Data.OleDb.OleDbCommand
sqlCommand.Connection = DBCon
sqlCommand.CommandText = SQLStr4
sqlCommand.Parameters.Add("@Hardware_Id", SqlDbType.VarChar).Value = HardwareId
sqlCommand.Parameters.Add("@Staff_Reported", SqlDbType.VarChar).Value = Staff
sqlCommand.Parameters.Add("@Problem_Description", SqlDbType.VarChar).Value = Description
sqlCommand.Parameters.Add("@Location", SqlDbType.VarChar).Value = Location

I keep on getting the error: Error reading database, No value given for one or more required parameters

thanks again

john

 
need to add something like this to the end of your insert statement.
FROM Hardware_Problems WHERE (Hardware_Problem_Id = @@IDENTITY)
notice the designation of @@identity:
You do not pass it NULL, you do not pass it anything. The database takes care of it.

You should have a parameter for each field. Just good programming practice.

also note the date field:
Add a parameter that is defined as a date.
You may have trouble having seperate fields for date and time, generally it is one field that contains date and time(at least in SQL)

Is Resolve_Flag boolean? What yype of field are you passing 'yes' to?

Once again, I recommend using the dataform wizard to write your insert statements for you until you become familiar with the concept/format.
 
Back
Top