|
-
Nov 26th, 2004, 03:53 PM
#1
Thread Starter
PowerPoster
sp_executesql
hey
how do you use sp_execute in C# for SQL????
what is the structure/syntax like? is there an example you guys can give me please?
-
Nov 27th, 2004, 01:15 AM
#2
PowerPoster
Is that a SQL built in stored procedure?
You can call stored procedures like:
SqlCommand command = new SqlCommand();
command.Connection = new SqlConnection("yourconnectionstring");
command.CommandText = "sp_execute";
command.CommandType = CommandType.StoredProcedure;
command.Connection.Open();
SqlDataReader rdr = command.ExecuteReader();
// Use the data reader here.
command.Connection.Close();
My code may be wrong as I hand typed it, but the idea is there. If this doesn't make sense to you at all, then you should look up the SqlCommand, SqlConnection, SqlDataReader, SqlDataAdapter, and DataSet objects in the help.
-
Nov 27th, 2004, 04:20 AM
#3
Thread Starter
PowerPoster
Thanks and yes it is a built in stored proc. I am trying to look for data insertion - since its different using this particular stored proc....and i need an example of data insertion using this stored proc
-
Nov 27th, 2004, 09:58 AM
#4
Thread Starter
PowerPoster
-
Nov 27th, 2004, 10:31 AM
#5
Frenzied Member
Are you sure you want to be using sp_execute (and not sp_executesql)? You see sp_execute a lot in the profiler along with sp_prepare, sp_unprepare.
Since Books Online has no help on this at all, makes you think Microsoft never intended developers to use it.
-
Nov 27th, 2004, 11:17 AM
#6
Thread Starter
PowerPoster
sp_executesql is the one i want, not sp_execute - i want to use sp_executesql
using insert statements, in C# with sp_executesql - how?
-
Nov 27th, 2004, 12:13 PM
#7
Frenzied Member
Quick example
Code:
SqlConnection con = new SqlConnection("Persist Security Info=False;Integrated Security=SSPI;database=PatriotDispatch;server=MIKELAP");
SqlCommand cmd = new SqlCommand("sp_executesql", con);
cmd.CommandType = CommandType.StoredProcedure;
string mySql = "INSERT INTO Logons (Logons_ORI, Logons_User_Name, Logons_Password) " +
"VALUES ('NM1234567', 'Techno', 'Edinburgh')";
SqlParameter param = cmd.Parameters.Add("@mySql", mySql);
con.Open();
int recordsAffected = cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show(recordsAffected.ToString() + " records affected.");
HTH,
Mike
-
Nov 27th, 2004, 12:14 PM
#8
Thread Starter
PowerPoster
thanks ill give it a shot
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|