![]() |
| |||||||
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
| Sponsored Links |
| ||||
| Hmmm...something about this doesn't quite look right. Why are you calling your DAL in your MySQLCommand? And why won't you use a Stored Procedure? ![]() Anyway, change CommandType.StoredProcedure to CommandType.CommandText, create a dynamic SQL string, but replace the variables in the string (i.e. @id) to a question mark. Code: Dim sql As String
sql = "INSERT INTO yourtable (id, street, housenumber, ...) VALUES(?,?,?, ...)"
Dim myCommand = New MySqlCommand(sql, myConnection)
myCommand.CommandType = CommandType.CommandText
myCommand.Parameters.AddWithValue("@id", myProjects.Idkey)
myCommand.Parameters.AddWithValue("@street", myProjects.TheDate)
myCommand.Parameters.AddWithValue("@houseNumber", myProjects.Name)
myCommand.Parameters.AddWithValue("@zipCode", myProjects.ProjectNumber)
myCommand.Parameters.AddWithValue("@city", myProjects.Description)
Dim returnValue As DbParameter
returnValue = myCommand.CreateParameter
returnValue.Direction = ParameterDirection.ReturnValue
myCommand.Parameters.Add(returnValue)
myConnection.Open()
myCommand.ExecuteNonQuery()
result = Convert.ToInt32(returnValue.Value)
myConnection.Close()
__________________ jmurrayhead Did I help you out? Make me popular by clicking the icon!If you found a post helpful, please click the button in the lower right-hand corner of the post.Powered by ASP.Net |
| ||||
| In My DAL i have a class that holds my queries, i did this for the fact that if i need to call data with diff filters, i simply just call the right query, and don't have to rebuild the function that talks to the db and gets the results. But as you said, why not use a stored procedure, well it's easier for me or some other developer to quickly write a query and save it in the query class and use it in where he needs it and then doesn't need to re-write anything else. Data collection will always be the same from a specific table, but the filtering that data can always change, get my drift. Shem |
| ||||
| JMH got in here while I was typing out an example, but I'll post it anyway: Code: Dim sqlStr as String = "INSERT INTO someTable " + _
"Values(@id, @street, @houseNumber, @zipCode, @city)"
Dim myCommand = New MySqlCommand(sqlStr, myConnection)
myCommand.Parameters.AddWithValue("@id", myProjects.Idkey)
myCommand.Parameters.AddWithValue("@street", myProjects.TheDate)
myCommand.Parameters.AddWithValue("@houseNumber", myProjects.Name)
myCommand.Parameters.AddWithValue("@zipCode", myProjects.ProjectNumber)
myCommand.Parameters.AddWithValue("@city", myProjects.Description)
Dim rowsAffected as Int32
myConnection.Open()
rowsAffected = smyCommand.ExecuteNonQuery()
myConnection.Close()
__________________ Wolffy ------------------------ Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary. |
| The Following 2 Users Say Thank You to Wolffy For This Useful Post: | ||
jmurrayhead (June 6th, 2008), Shem (June 6th, 2008) | ||
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Query Counts | Jaykappy | Microsoft Access | 13 | May 14th, 2008 01:39 PM |
| SQL VBA Query | Jaykappy | Microsoft Access | 12 | May 8th, 2008 09:30 AM |
| Using Dropdown List Value in Database SQL Query | richyrich | Classic ASP | 0 | April 2nd, 2008 10:05 AM |
| Sponsored Links |
| ASP.NET Resource Index a directory of ASP.NET tutorials, applications, scripts, assemblies and articles for the novice to professional developer. Free Web Directory Including Chats and Forums Resources, Offer automatic, instant and free directory submissions. | URLZ Web Directory URLZ Web Directory Free Web Directory - Add Your Link The Little Web Directory | Free Web Directory Pegasus free web directory is a free directory organised by categories. Web Directory & SEO Services dirroot web directory |