|
I have my database called patients.mdb and I am using the below code to read from it (part of the code):
<br />
<br />
OdbcDataReader reader = command.ExecuteReader(); <br />
<br />
while (reader.Read())<br />
{<br />
rTxtBxMC.Text = Convert.ToString(<br />
reader[0]);<br />
} <br />
<br />
reader.Close();<br />
<br />
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?
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
What Simon said. Also look at INSERT and UPDATE in SQL, both of which use ExecuteNonQuery .
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
DatabaseAccessor[^]
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!
|
|
|
|
|
hi
i try to backup and restore database using sql-server 2008 and got error.
to backup i done this:
BACKUP DATABASE MyDB TO DISK='d:\MyDB.BAK' (and its work fine)
to restore i done this:
USE MASTER RESTORE DATABASE MyDB FROM DISK='d:\MyDB.BAK
and got this error:
Msg 3159, Level 16, State 1, Line 7
The tail of the log for the database "MyDB " has not been backed up. Use BACKUP LOG WITH NORECOVERY to backup the log if it contains work you do not want to lose. Use the WITH REPLACE or WITH STOPAT clause of the RESTORE statement to just overwrite the contents of the log.
Msg 3013, Level 16, State 1, Line 7
RESTORE DATABASE is terminating abnormally.
Where I'm wrong ? what is missing ?
thank's in advance
|
|
|
|
|
The database MyDB is already exists. Consider using WITH REPLACE to overwrite the database.
Here [^] is more about restore.
|
|
|
|
|
thank's for the help !
can i get a simple sample for what i need to do with my example ?
|
|
|
|
|
Perhaps this would help
RESTORE DATABASE MyDB FROM DISK='d:\MyDB.BAK' WITH REPLACE
|
|
|
|
|
thank's for the help, but i got this error:
Msg 3101, Level 16, State 1, Line 7
Exclusive access could not be obtained because the database is in use.
Msg 3013, Level 16, State 1, Line 7
RESTORE DATABASE is terminating abnormally.
|
|
|
|
|
You can't do a restore on a database that is in use. So you will first have to kill all clients accessing the database, either by stopping them or forcefully disconnecting them from the database. Check the activity using the 'Activity Monitor'.
|
|
|
|
|
Well your error message suggest the problem. Close all applications using the database you want to restore. Close all SSMS windows using the database you want to restore. And when you are running restore query use master database.
Try to read the error messages in all cases. That will help you understand any problem.
|
|
|
|
|
Hi
I need to create an inventory database using sql server 2008 and want to know on how i will proceed, what are the steps,etc ? can someone please provide me with some advice?
Thanks
|
|
|
|
|
0) Download SQL Server 2008 R2 Express[^]
1) Install it
2) Read up on relational database management systems
3) Read up on database normalisation
4) Perform an inventory of what you have and decide how you want to represent it in your database
5) Ask more specific questions in online fora
Really, it depends on what you have and how you picture it in your head.
The more tables the better!
|
|
|
|
|
PIEBALDconsult wrote: The more tables the better
Ehm, only if you really need them...
"When did ignorance become a point of view" - Dilbert
|
|
|
|
|
I once inherited a database in whcih the original programmer had created seperate tables for each and every field - eg instead of:
Table "clients":
ID
Name
Address
PostCode
etc
They had:
Table "clients"
ID
Name
Table "addresses"
ClientID
Address
Table "PostCodes"
ClientID
PostCode
etc et-bloody-cetera.... dozens of tables.
You can just imagine the SQL statements....
|
|
|
|
|
If you have a table with very many columns and you often select just a subset of them, then I can understand if you split the table for performance reasons. But what you inherited is just ridiculous.
And it doesn't have anything to do with normalization.
"When did ignorance become a point of view" - Dilbert
|
|
|
|
|
Look here:
Data Models[^]
for database design options.
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
thanks that help a lot, cheers
|
|
|
|