Index: S.No - Questions Page No
Index: S.No - Questions Page No
Index: S.No - Questions Page No
7. Write a C sharp program for jagged array and display its item
through foreach loop.
using System;
public class Program
{
public static void Main(string[] args)
{
string[][] str = new string[5][];
str[0] = new string[5];
str[1] = new string[10];
str[2] = new string[20];
str[3] = new string[50];
str[4] = new string[10];
str[0][0] = "Pune";
str[1][0] = "Kolkata";
str[2][0] = "Bangalore";
str[3][0] = "The pink city named Jaipur";
str[4][0] = "Hyderabad";
foreach(string[] i in str)
foreach(string s in i)
if(!string.IsNullOrEmpty(s))
Console.WriteLine(s);
Console.ReadKey();
}
}
}
}
}
21.Write a program using ADO.net to insert, update, delete data in
back end.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection c = new SqlConnection("server=(localdb)\\
MSSQLLocalDB;integrated security=True;database=Master");
private void button1_Click(object sender, EventArgs e)
{
SqlCommandcmd = new SqlCommand("insert into Mydb
values(@id,@name,@course,@age)",c);
cmd.Parameters.AddWithValue("@id",textBox1.Text);
cmd.Parameters.AddWithValue("@name", textBox2.Text);
cmd.Parameters.AddWithValue("@course", textBox3.Text);
cmd.Parameters.AddWithValue("@age",textBox4.Text);
c.Open();
cmd.ExecuteNonQuery();
c.Close();
MessageBox.Show("inserted successfully!!");
}
private void button3_Click(object sender, EventArgs e)
{
SqlCommandcmd = new SqlCommand("delete from Mydb
where id='"+textBox1.Text+"'",c);
c.Open();
cmd.ExecuteNonQuery();
c.Close();
MessageBox.Show("record deleted successfully!!");
}
private void button2_Click(object sender, EventArgs e)
{
SqlCommandcmd = new SqlCommand("update Mydb set
name=@name,course=@course,age=@age where id=@id", c);
cmd.Parameters.AddWithValue("@id", textBox1.Text);
cmd.Parameters.AddWithValue("@name",textBox2.Text);
cmd.Parameters.AddWithValue("@course", textBox3.Text);
cmd.Parameters.AddWithValue("@age", textBox4.Text);
c.Open();
cmd.ExecuteNonQuery();
c.Close();
MessageBox.Show("record updated successfully!!");
}
}
}