|
-
May 15th, 2009, 11:40 AM
#1
Thread Starter
Hyperactive Member
parameterized query update question
As you may have seen in my other post, I have to switch over an all text SQL statement based database interaction program to using parameterized queries instead.
I remember doing it this way in college but I don't seem to be able to recall one part of it. The program I wrote back then and some code samples here both point to doing the code as I did so far:
Code:
m_strSQL = "UPDATE [OWNER DATA] SET [FIRST NAME] = @strFName"
m_strSQL &= ",[LAST NAME] = @strLName"
...etc
Dim upCMD As New OleDb.OleDbCommand(m_strSQL, m_Connection)
upCMD.Parameters.Add("@strFName", OleDb.OleDbType.Char, 30, "[First Name]")
...etc
m_DataAdapter.UpdateCommand = upCMD
m_DataAdapter.Update()
So by the second to last line there it has the SQL statement build and loaded into the command object and all the data for the fields is there so I just need it to actually do the update but that m_DataAdapter.Update() command is asking for a dataset to use to update it. My program is not set up to read in a dataset from the database, modify it, and send it back using that command so that whole model doesn't work for me in this case. Why can't it just take the SQL statement and run it without asking for a dataset to use? Am I missing something really obvious here?
My old version with just strings used:
Dim upCMD As New OleDb.OleDbCommand(m_strSQL, m_Connection)
intCount = upCMD.ExecuteNonQuery()
and tada, it ran the SQL statement and that's that. Can I just do that with a parameterized query too without using the adapter.update()? And for bonus points, why the heck did I use that command in my old college program cuz I sure don't know? lol.
I tried to end process on Visual Studio 2005
but PETA stopped me saying it's smart enough
to be a living creature 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|