C#.. visual studio
2.6K subscribers
2 links
Download Telegram
Channel created
Channel photo updated
C# ASP.NET CODE


SAVE BUTTON CODE

protected void btnsave_Click(object sender, EventArgs e)
{
string constring = @"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\lkj.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
int roll = int.Parse(txtroll.Text.ToString());
string name = txtname.Text.ToString();
SqlConnection con = new SqlConnection(constring);
con.Open();
SqlCommand cmd = new SqlCommand("insert into tblstud(roll,name) values('"+roll+"','"+name+"')",con);

cmd.Parameters.AddWithValue("@roll",roll);
cmd.Parameters.AddWithValue("@name", name);
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert('saved successfully')</script>");
}













UPDATE BUTTON CODE

protected void btnupdate_Click(object sender, EventArgs e)
{
string constring = @"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\lkj.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
int roll = int.Parse(txtroll.Text.ToString());
string name = txtname.Text.ToString();
SqlConnection con = new SqlConnection(constring);
con.Open();
SqlCommand cmd = new SqlCommand("update tblstud set roll='"+roll+"',name='"+name+"' where roll='"+roll+"'", con);

cmd.Parameters.AddWithValue("@roll", roll);
cmd.Parameters.AddWithValue("@name",name);
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert('updated successfully')</script>");
}






DELETE BUTTON CODE



protected void btndelete_Click(object sender, EventArgs e)
{
string constring = @"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\lkj.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
int roll = int.Parse(txtroll.Text.ToString());
string name = txtname.Text.ToString();
SqlConnection con = new SqlConnection(constring);
con.Open();
SqlCommand cmd = new SqlCommand("delete from tblstud where roll='"+roll+"'", con);

cmd.Parameters.AddWithValue("@roll", roll);
cmd.Parameters.AddWithValue("@name", name);
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert('deleted successfully')</script>");
}









GRIDVIEW CODE-select row and show value in related textbox: populate values




protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
txtroll.Text = GridView1.SelectedRow.Cells[1].Text;
}
database name ljk.mdf tablename tblstud
columns roll --name
For windos form messagebox code is msgBox.show("saved successful");
Hello word program in console application

console. WriteLine("hello world");


Or

System.console. writeLine("hello world");
Explain the control statements in c# with suitable example.
Forwarded from Deleted Account
Control statements in c#

Means branching and looping


Branching includes

If -else
Switch-case
......

Looping includes

For
While
Do while
For each
Forwarded from Deleted Account
If(a>0)
{
console. WriteLine("positive num");
}
else
{
console. WriteLine("negative num");
}

console. ReadKey();
Forwarded from Deleted Account
Int d=2;
Switch(d)
{
Case 1:

console. WriteLine("sunday");
break;

Case 2:

console. WriteLine("monday");
break;

Case 3:

console. WriteLine("tuesday");
break;

Default:

console. WriteLine("not a day");



}