C#.. visual studio
2.6K subscribers
2 links
Download Telegram
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");



}
Loops
Forwarded from Deleted Account
int i;
for(i=1;i<=10;i++)
{
console. WriteLine(i);

}
Forwarded from Deleted Account
Int i=1;
While (i<=10)
{
console. WriteLine(i);
i++;
}
Forwarded from Deleted Account
Int i=1;
do
{
console. WriteLine(i);
i++;
}
while (i<=10)
Loop output is same
12345678910
Forwarded from Bsc computor scienc (science Ks)
C# Program to Swap two Numbers

using System;


namespace Program
{
class Program
{
static void Main (string [ ] args)
{
int num1, num2, temp ;

Console . WriteLine (" Enter the First Number : " ) ;


num1 = int .Parse
( Console. ReadLine( )) ;


Console . WriteLine (" Enter the Second Number : " ) ;
num2 = int .Parse
( Console. ReadLine( )) ;
temp = num1 ;
num1 = num2 ;
num2 = temp ;

Console . WriteLine (" After Swapping : " );

Console . WriteLine ("\n First Number : " + num1 );

Console . WriteLine("
Second Number : " + num2 );



Console . ReadLine () ;
}
}
}
Forwarded from Bsc computor scienc (science Ks)
Here is the output of the C# Program:
Enter the First Number : 23
Enter the Second Number : 25
After Swapping :
First Number : 25
Second Number : 23
Forwarded from Deleted Account
static void SwapByRef(ref int x, ref int y)
{
int temp = x;
x = y;
y = temp;
}
When you call the SwapByRef method, use the ref keyword in the call, as shown in the following example.
C#
static void Main()
{
int i = 2, j = 3;
System.Console.WriteLine("i = {0} j = {1}" , i, j);

SwapByRef (ref i, ref j);

System.Console.WriteLine("i = {0} j = {1}" , i, j);

// Keep the console window open in debug mode.
System.Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
}
/* Output:
i = 2 j = 3
i = 3 j = 2
*/