Showing posts with label sqlcommand. Show all posts
Showing posts with label sqlcommand. Show all posts

Tuesday, June 1, 2010

Delete data using sqlcommand


Delete data using sqlcommand,sql,command,

Delete Button code
  protected void button_delete_Click(object sender, EventArgs e)
    {
        sqlgetdata getdata = new sqlgetdata ();
        getdata.deletemain(Convert.ToInt32(TextBox_stuid.Text));
        Label_reply.Text = "Record deleted";
        TextBox_stuid.Text = "";
        TextBox_name.Text = "";
        TextBox_course.Text = "";
        TextBox_fee.Text = "";
    }
public void deletemain(Int32 ss)
    {
        Int32 sa = ss;
        string querystring = "delete from student where stu_id=" + sa;
string sqlconstring = "Data Source= SHYAM\\SQLEXPRESS ;initial catalog=college; integrated security=True ";    
SqlConnection sqlcn = new SqlConnection(sqlconstring);
Sqlcommand sqlcmd=new Sqlcommand(querystring,sqlcn);
sqlcn.Open();
sqlcmd.ExecuteNonQuery();
sqlcn.Close();
    }
 
increase your webtraffic

Friday, April 30, 2010

Select data using SqlCommand


Select data using sqlcommand

selectButton event
It is step3 procedure

protected void btn_select_Click(object sender, EventArgs e)
    {

        sqlgetdata getdata=new sqlgetdata();

       classvar seletvar= getdata.searchmain(Convert.ToInt32(TextBox1.Text));

       TextBox2.Text = Convert.ToString(seletvar.name);
       TextBox3.Text = Convert.ToString(seletvar.course);
       TextBox4.Text = Convert.ToString(seletvar.fee);

        Label1.Text = "record fetched";

    }




Variable class


It is step4 procedure


public class classvar
{
    public int id{get;set;}

    public string name { get; set; }
    public string course { get; set; }
    public int fee { get; set; }
}





It is step5 procedure


public classvar searchmain(Int32 ss)
    {
        Int32 sa = ss;
        string sqlquerystring= "select * from student where stu_id="+ sa;

       
             string sqlconstring= "Data Source= SHYAM-6E8C5C74B\\SQLEXPRESS ;initial catalog=college; integrated security=True ";
 SqlConnection sqlcn= new SqlConnection(sqlconstring);

Sqlcommand sqlcmd=new Sqlcommand(sqlquerystring,sqlcn);
sqlcn.Open();
SqlDataReader sqlre= sqlcmd.ExecuteReader();
        classvar seletvar = new classvar();
        while (sqlre.Read())
        {
            seletvar.fee = re["fee"].ToString();
            seletvar.name = re["name"].ToString();
            seletvar.course = re["course"].ToString();


        }
            sqlre.Close();
           sqlcn.Close();
        return seletvar;
}














See Status of the blog



Monday, April 26, 2010

Insert data using sqlcommand




Insert data using sqlcommand,usingsimple,datasqlclassusing,sqlcommand,simpledatausing,datasqlcommand,usingsqlcommand,sqlcommandsqlclass,simplesqlclasssimple,sqlcommandusing,datasqlcommandsimple,sqlclassdata,simplesqlclasssqlcommand,simplesqlcommand,datasimple,sqlcommanddatasimple,usingdatasqlcommand,simplesqlclassusing,sqlcommanddatausing,usingsqlcommandsqlclass,

It is step3 procedure

Insert data using sqlcommand

Save button event
protected void btninsert_Click(object sender, EventArgs e)
{
first f = new first();
f.id = Convert.ToInt32(TextBox1.Text);
f.name = TextBox2.Text;
f.course = TextBox3.Text;
f.fee = Convert.ToInt32(TextBox4.Text);

datac c=new datac();
c.insertmain(f);
Label1.Text = "record inserted";
}



It is step4 procedure


Variable class

public class first
{
public int id{get;set;}

public string name { get; set; }
public string course { get; set; }
public int fee { get; set; }
}

It is step5 procedure

Data class

Public void insertmain(first f)
{
string s= "insert into student values(" + f.id + ",'" + f.name + "','" + f.course + "'," + f.fee + ")";

string constring = "Data Source= SHYAM-6E8C5C74B\\SQLEXPRESS ;initial catalog=college; integrated security=True ";

SqlConnection cn = new SqlConnection(constring);
SqlCommand cmd = new SqlCommand(cmd, cn);
cn,Open();
cmd.ExecuteNonQuery();
cn.Close();
}