Oledbcommand not updating
SQL statements that modify data (such as INSERT, UPDATE, or DELETE) do not return rows.
Similarly, many stored procedures perform an action but do not return rows.
Execute Non Query() // Assumes connection is a valid Sql Connection. Open(); string query String = "INSERT INTO Customers " "(Customer ID, Company Name) Values(' NWIND', ' Northwind Traders')"; Sql Command command = new Sql Command(query String, connection); Int32 records Affected = command.
Execute Non Query(); The following code example executes the stored procedure created by the sample code in Performing Catalog Operations.
All we need is to tell it which driver to use and where to find the database file. Then we give it the connection string and open the connection…
If this had been a database like My SQL located on another server, we would have to specify IP address info as well as port. Notice in our code above we create a new Ole Db Connection and give it a connection string to tells it where to find and to use our OLEDB 4.0 driver.
So how do we get this stupid name column out of our table “Employees” of the access database and into a control? One is to connect to the database, another thing is to query the database for the info and lastly we put that info into our source control… Connecting to the database is pretty straight forward and really starts out with picking the right connection object from the System. Since Access can be “accessed” through the OLEDB setup we can use the Ole Db Connection class for that. This is nothing but a string that tells the class where to find the database, what driver (or DSN) to use, any username and passwords to login to the database, and any security features we will need to implement for our access.
Value) // Assumes connection is a valid Sql Connection.
Execute Non Query(); Int32 category ID = (Int32) command.
No rows are returned by the stored procedure, so the Execute Non Query method is used, but the stored procedure does receive an input parameter and returns an output parameter and a return value.
For the Ole Db Command object, the Return Value parameter must be added to the Parameters collection first.
Once we have it in the bucket, we can use the data independent of the connection or adapter.