-
how to close mycmd
private void Button1_Click(object sender, System.EventArgs e)
{
string status;
status="p";
SqlConnection myConn = new SqlConnection(ConfigurationSettings.AppSettings["con"]);
try
{
myConn.Open();
SqlCommand myCmd1=new SqlCommand("select C_Item_Id,C_Item_Var from CounterTable where C_Id=1",myConn);
SqlDataReader dr1;
dr1=myCmd1.ExecuteReader();
while(dr1.Read())
{
int intuid=Convert.ToInt16( dr1.GetValue(0).ToString());
string stritemval=dr1.GetValue(1).ToString();
strreid=stritemval+intuid;
intretid=intuid+1;
}
dr1.Close();
SqlCommand myCmd2=new SqlCommand("update CounterTable set C_Item_Id=@rid where C_Id=1",myConn);
myCmd2.Parameters.Add("@rid",intretid);
myCmd2.ExecuteNonQuery();
SqlCommand myCmd3 = new SqlCommand("insert into User_Details(User_Id,User_Name,User_Gender,User_Address,User_City,User_Country,User_Code,U ser_Telephone,User_Mobile,User_Comments,User_Status) values(@name,@gender,@address,@city,@country,@zip,@tel,@mob,@status)", myConn);
myCmd3.Parameters.Add("@uid",strreid);
myCmd3.Parameters.Add("@name",txtboxName.Text.ToString());
myCmd3.Parameters.Add("@gender",rdoGender.SelectedItem.ToString());
myCmd3.Parameters.Add("@address",txtboxAddr.Text.ToString());
myCmd3.Parameters.Add("@city",txtboxCity.Text.ToString());
myCmd3.Parameters.Add("@country",drpDwnCountry.SelectedValue.ToString());
myCmd3.Parameters.Add("@zip",txtboxPostCode.Text.ToString());
myCmd3.Parameters.Add("@tel",txtboxTel.Text.ToString());
myCmd3.Parameters.Add("@mob",txtboxMob.Text.ToString());
myCmd3.Parameters.Add("@status",status);
myCmd3.ExecuteNonQuery();
SqlCommand myCmd4 = new SqlCommand("insert into FrmUsrlogin(User_Id,User_Loginid,User_Loginpwd) values()", myConn);
myCmd4.Parameters.Add("@uid",strreid);
myCmd4.Parameters.Add("@loginid",txtboxlogin.Text.ToString());
myCmd4.Parameters.Add("@loginpwd",txtboxPassword.Text.ToString());
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
myConn.Close();
}
-
Just use one command over and over again:
SqlCommand myCmd1=new SqlCommand("select C_Item_Id,C_Item_Var from CounterTable where C_Id=1",myConn);
when you are done using your command, do the following
myCmd1.Dispose();
myCmd1 = null; //or whatever the equivalent is in C# of NOTHING
when you need to use it again, use the new sqlcommand again
myCmd1=new SqlCommand("sql statement",myConn);
new to programming but getting ther
Similar Threads
-
Replies: 2
Last Post: 05-25-2005, 04:31 AM
-
By Sachin in forum VB Classic
Replies: 1
Last Post: 12-29-2000, 03:05 AM
-
By Leonardo Bosi in forum VB Classic
Replies: 10
Last Post: 05-09-2000, 04:29 PM
-
By Dajing Hu in forum VB Classic
Replies: 2
Last Post: 03-14-2000, 12:07 PM
-
By Dajing Hu in forum VB Classic
Replies: 0
Last Post: 03-14-2000, 11:15 AM
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks