Last post May 24, 2011 04:34 AM by Decker Dong - MSFT
May 20, 2011 07:01 AM|pritams|LINK
Can I define Insert query only once as in stored procedures for access database?
May 20, 2011 07:31 AM|bhavik.y.shah|LINK
Yes you can
but in that you need to pass field and table name dynamically.
May 21, 2011 02:00 AM|KumarHarsh|LINK
Secondly if you make a query in mdb like in emp table(4 columns)
INSERT INTO Employee ( empid, fname, lname, deptid ) values(?,?,?,?)
<div></div> It will ask for paramter.
I think you can invoke this from asp.net and pass parameter)
May 21, 2011 02:39 AM|pritams|LINK
How can I pass field and table name dynamically?
May 22, 2011 10:36 PM|decker dong - msft|LINK
First I beg your pardon but I cannot understand how you can use query in Access as StoredProcdure? I know that Access db doesn't support SP.
And If you want to dynamically craete an insert with different tables as well as its names. I think you use something like this:
public boolean DynamicInsert(string insertsql,OleDbParameterparameters)
using (OleDbConnection con = new OleDbConnection(Your conn str))
OleDbCommand cmd = new OleDbCommand(insertsql,con);
You can call this method as:
DynamicInsert("insert into tableA values(@a,@b)",new OleDbParameter
With different kinds of insert sql statement as parameters, you should finish the task.
May 23, 2011 04:53 AM|hans_v|LINK
Decker Dong - MSFT
First I beg your pardon but I cannot understand how you can use query in Access as StoredProcdure? I know that Access db doesn't support SP
Access doesn't support Stored Procedures. However, it does support stored queries (single sql statements) that you can execute just like SQL stored procedures...
May 23, 2011 09:03 PM|decker dong - msft|LINK
Oh, you mean just like the 2man's or what I say, hans_v?
Just use OleDbCommand+Your sql statement?
Thx again. Correct me if I'm wrong：）
May 24, 2011 03:45 AM|hans_v|LINK
I mean this: In Access, you can store a query named query1, for example:
PARAMETERS @Field1 Text ( 255 ), @ID Long;
UPDATE table1 SET Field1 = @Field1 WHERE ID = @ID
Then you can do something like:
Using cn As New Data.OleDb.OleDbConnection("youconnectionstring")
Using cmd As New Data.OleDb.OleDbCommand("query1", cn)
cmd.CommandType = Data.CommandType.StoredProcedure
May 24, 2011 04:34 AM|decker dong - msft|LINK
Oh man, you are really a hero——hans_v!
Specialized in Access...
Yours is right.
I've also learnt a lot from you
Hope we can futher discuss more on some issues