Writting to a database
-
I have my database called patients.mdb and I am using the below code to read from it (part of the code):
OdbcDataReader reader = command.ExecuteReader(); while (reader.Read()) { rTxtBxMC.Text = Convert.ToString( reader[0]); } reader.Close();
How to you write to a database of this type? -
I have my database called patients.mdb and I am using the below code to read from it (part of the code):
OdbcDataReader reader = command.ExecuteReader(); while (reader.Read()) { rTxtBxMC.Text = Convert.ToString( reader[0]); } reader.Close();
How to you write to a database of this type?So you discovered one method (ExecuteReader) of the OdbcCommand class, and now you want someone to spoon feed you on another of its methods? too lazy to read a single page on MSDN? Google broke down? What gives? X|
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
I have my database called patients.mdb and I am using the below code to read from it (part of the code):
OdbcDataReader reader = command.ExecuteReader(); while (reader.Read()) { rTxtBxMC.Text = Convert.ToString( reader[0]); } reader.Close();
How to you write to a database of this type?Have to agree with Luc on that one, BUT look into the different type of execute from the command object. depending on your database type and how you want to execute the query i.e. SQL or stored procedures you need to read up on ExecuteNonQuery[^]
As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
-
So you discovered one method (ExecuteReader) of the OdbcCommand class, and now you want someone to spoon feed you on another of its methods? too lazy to read a single page on MSDN? Google broke down? What gives? X|
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Thanks for the answer, however just because something seems simple to you doesn't mean it will be to the next arrogent SB.
-
Thanks for the answer, however just because something seems simple to you doesn't mean it will be to the next arrogent SB.
if you want to achieve anything at all at programming, you need to learn and help yourself first of all; only when that fails, ask a specific question here and people will be glad to help out. Laziness is not appreciated around here, so start using Google, look at MSDN, buy and study a book, and read some of those nice articles on CodeProject. It is all there to provide basic information and much more. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
I have my database called patients.mdb and I am using the below code to read from it (part of the code):
OdbcDataReader reader = command.ExecuteReader(); while (reader.Read()) { rTxtBxMC.Text = Convert.ToString( reader[0]); } reader.Close();
How to you write to a database of this type?What Simon said. Also look at
INSERT
andUPDATE
in SQL, both of which useExecuteNonQuery
.CQ de W5ALT
Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software
-
I have my database called patients.mdb and I am using the below code to read from it (part of the code):
OdbcDataReader reader = command.ExecuteReader(); while (reader.Read()) { rTxtBxMC.Text = Convert.ToString( reader[0]); } reader.Close();
How to you write to a database of this type?Tichaona J wrote:
Convert.ToString(
I suspect that that is completely needless in this case, if the value in the database is already a string then a simple cast is all you need. Don't use the Convert class!
-
Have to agree with Luc on that one, BUT look into the different type of execute from the command object. depending on your database type and how you want to execute the query i.e. SQL or stored procedures you need to read up on ExecuteNonQuery[^]
As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
ExecuteReader can execute any SQL statement (and more than one at time in some cases); ExecuteNonQuery and ExecuteScalar call it in the background.
-
ExecuteReader can execute any SQL statement (and more than one at time in some cases); ExecuteNonQuery and ExecuteScalar call it in the background.
I always thought ExecuteReader (one or more rows) and ExecuteScalar (single value) return values from the database, where as ExecuteNonQuery only returns the number of rows returned, i.e a write which the Op was asking about Is the ExecuteReader executing a an insert / update or delete statement something it can do but not by intentional design?
As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
-
I always thought ExecuteReader (one or more rows) and ExecuteScalar (single value) return values from the database, where as ExecuteNonQuery only returns the number of rows returned, i.e a write which the Op was asking about Is the ExecuteReader executing a an insert / update or delete statement something it can do but not by intentional design?
As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
Read up more on DataReaders -- they can do anything. The others simply wrap it.
-
Read up more on DataReaders -- they can do anything. The others simply wrap it.
Cheers will do
As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.