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? :)
Printable View
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? :)
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.
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 :)
anyone?
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.
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?
Quick example
HTH,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.");
Mike
thanks :) ill give it a shot ;)