Hi, I believe this is what you are looking for..??
If you are trying to use the same with "Using" block, its a best practice to use( as far as i know).
string connstr = ConfigurationManager.ConnectionString["Conn"].ConnectionString; or .ToString(); //"Conn" is the name of the connectionstrings that we include in the web.config file.
In method Page_Load or any other:
using (sqlconnection conn = new sqlconnection(connstr))
if(conn.State == ConnectionState.Closed || conn.State == ConnectionState.Broken)
conn.Open(); // its better to open your connection before executing your command.
string sql = "write your sql query here"; // if you have a stored procedure, this is not necessary.
using (sqlcommand cmd = new sqlcommand( sql, conn))
// if there are any parameters, declare them and add the parameter.
// cmd.Parameters.Add(prm); if no paramerts then no need to add them.
// If you have to fill the data use some data adapter.
returnvalue = cmd.ExecuteNonQuery();
Awesome Coding !! :)
Balajikcp8, if this helps please login to Mark As Answer. |
Reply | Alert Moderator