Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I am getting an error when I attempt to insert a record. Here is my code

'insert
sql = "insert into EMPLOYEES values (@UserID,'" + _
txtFirstName.Text + "','" + txtLastName.Text + "','" + _
txtAddress.Text + "','" + txtCity.Text + "','" + txtState.Text + "','" _
+ txtZipCode.Text + "',#" + txtHireDate.Text + "#,'" + txtTitle.Text + "')"
Dim func As New CommonFunctions()
Dim cmdIns = New OleDb.OleDbCommand(sql, conn)
Dim parm1 = New OleDb.OleDbParameter("@UserID", OleDbType.Integer)
parm1.value = func.getNextID("EMPLOYEES")
cmdIns.parameters.add(parm1)
conn.Open()
cmdIns.executenonquery()

conn.Close()
cmdIns = Nothing

It is failing on the line attempting to do the ExecuteNonQuery(). I

noticed that the OleDbCommand object did not recognize the

ExecuteNonQuery method when I typed it. I'm assuming that

might have something to do with the problem.

 

 

I am a newbie at this and have a question about how I'm going

about doing this. I have created a dataset that is bound to a

datagrid. The grid populates fine. I understand, that I should be

able to update/delete those records. However, if I want to insert

a new record into the datagrid, is this the correct way to do it ?

I'm going to a new page, allowing the user to enter the

information into a form, and then I have the above code

triggering. Am I doing this correctly?

 

Does anyone have any thoughts?

I appreciate any advice

Rick

Edited by Robby
Posted

try it this way:

 

Dim cmdIns = New OleDb.OleDbCommand()

 

cmdIns = New OleDb.OleDbCommand(sql, conn)

 

I sometimes get error like this and find splitting the lines into two works

My website
  • Leaders
Posted

Use "As", the same as you did for "func". Also, since you're having this problem, you might want to turn Option Strict On, which would have caught this.

 

Dim cmdIns As New OleDb.OleDbCommand(sql, conn)
Dim parm1 As New OleDb.OleDbParameter("@UserID", OleDbType.Integer)

 

hog, hopefully you mistyped and meant something more like this:

Dim cmdIns = OleDb.OleDbCommand
cmdIns = New OleDb.OleDbCommand(sql, conn)

 

The way you've got it right now actually creates two instances, one on the first line, which immediately gets thrown away with the second line. Not good.

--tim
Posted

Tim,

Thanks for your help. That was the ticket.

 

As I mentioned, I have a dataset bound to the data grid. I've included a Button column that has the Edit, Update, and Cancel linked buttons on the grid. What do I have to do to be able to edit the record. When I click the Edit link button, nothing is happening. I'm sorry if this is a stupid question, but I'm missing the idea here.

 

From what I read, I have to program the Grid_Edit event. But what am I looking to do? What I would like to do is open the same form that they insert new users to open with the information for the specific row they have clicked the Edit link button. I have the ID column in the grid hidden, and I'd like to pass that ID to the response.redirect in the Grid_Edit event. Can I do that?

 

Thanks again for your help.

Rick

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...