how to close mycmd


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: how to close mycmd

  1. #1
    Join Date
    Aug 2006
    Posts
    113

    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();
    }

  2. #2
    Join Date
    Jun 2004
    Location
    Pakistan
    Posts
    292
    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

  1. java popup auto close..?
    By paulk in forum Java
    Replies: 2
    Last Post: 05-25-2005, 05:31 AM
  2. Re: code to close DOS prompt from VB
    By Sachin in forum VB Classic
    Replies: 1
    Last Post: 12-29-2000, 04:05 AM
  3. Close all user applications
    By Leonardo Bosi in forum VB Classic
    Replies: 10
    Last Post: 05-09-2000, 05:29 PM
  4. Replies: 2
    Last Post: 03-14-2000, 01:07 PM
  5. Replies: 0
    Last Post: 03-14-2000, 12:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center