Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 39

PRACTICAL FILE

C#

VARNIT JAIN
0191BCA056
Q. Write a c# program to print Hello and your name in a separate line

Q. Write a c# program to print the sum of two numbers.

Q. Write a c# program to that takes a number as input and print its multiplication table.
Q. Write a c# program to print the result of dividing two numbers.

Q. Write a c# program to swap two number.


Q. Write a c# program that take four numbers as input to calculate and print the average.
Q. Write a c# program that takes a number and a width also a number, as input then display a triangle of
that width, using that number.

Q. Write a c# program to check whether a given number is positive or negative.


Q. Write a c# program to find whether a given year is a leap year or not.
Q. Write a c# program to demonstrate Command line arguments processing.
Q. Write a c# program to find the roots of Quadratic Equations

Q. Write a c# program to find the second largest element in a single dimensional array.
Q. Write a c# program to demonstrate boxing and unboxing.
Q. Write a c# program to implement stack operations
Q. Write a c# program to find the sum of all the elements present in a jagged array of 3 inner array
Q. Design a simple calculator using Switch Statement in c#.
PART 2

Q. Write a c# program to check whether a number is palindrome or not


Q. Write a c# program to multiply two matrices using rectangular array
Q. Write a c# program to reverse a given string
Q. Write a c# program to display the date in various formats
Q. Write a c# program to find difference between two dates
Q. Write a c# program to concatenate two string

Q. Write a c# program to find sub-string


Q. Write a c# program to replace sub-string
Q. Write a c# program to find the sum of all elements of the array
Q. Write a c# program to demonstrate operator overloading
Q. Write a c# program to demonstrate abstract class and abstract methods
Q. Write a c# program to build a class which implements an interface which already exists
Q. Write a c# program to illustrate the use of different properties
PART 6

Create Database
Create database userdata;
C=Create Table user_info
CREATE TABLE user_info( `id` INT NOT NULL AUTO_INCREMENT , `names` VARCHAR(50) NOT
NULL , `username` VARCHAR(20) NOT NULL , `password` VARCHAR(50) NOT NULL , PRIMARY KEY
(`id`)) ;

C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
//add this for MessageBox
using System.Windows.Forms;

// add data function classes


using System.Data;

namespace LoginSysten
{
public class Config
{
string ConectionString = ""; // save connection string
public MySqlConnection connection = null;
public string server = "127.0.0.1";// MySQL host / ip of the computer
public string user = "root";// MySQL user
public string password = "";// MySQL password
DataSet ds;
DataTable dt;
public string Table = "user_info"; // initialize db table
public string ConnectionType = "";
string RecordSource = "";

DataGridView tempdata;

public Config()
{

// function to connect to the database


public void Connect(string database_name)
{
try
{

ConectionString = "SERVER=" + server + ";" + "DATABASE=" + database_name + ";" + "UID="


+ user + ";" + "PASSWORD=" + password + ";";

connection = new MySqlConnection(ConectionString);


}
catch (Exception E)
{
MessageBox.Show(E.Message);
}
}

// Function to execute select statements


public void ExecuteSql(string Sql_command)
{
nowquiee(Sql_command);

// creates connection to MySQL before execution


public void nowquiee(string sql_comm)
{
try
{
MySqlConnection cs = new MySqlConnection(ConectionString);
cs.Open();
MySqlCommand myc = new MySqlCommand(sql_comm, cs);
myc.ExecuteNonQuery();
cs.Close();

}
catch (Exception err)
{

MessageBox.Show(err.Message);
}
}

// function to execute delete , insert and update


public void Execute(string Sql_command)
{
RecordSource = Sql_command;
ConnectionType = Table;
dt = new DataTable(ConnectionType);
try
{
string command = RecordSource.ToUpper();

//======================if sql contains


select==========================================
MySqlDataAdapter da2 = new MySqlDataAdapter(RecordSource, connection);

DataSet tempds = new DataSet();


da2.Fill(tempds, ConnectionType);
da2.Fill(tempds);

//==================================================================================
====
}
catch (Exception err) { MessageBox.Show(err.Message); }
}

// function to bring selected results based on column name and row index
public string Results(int ROW, string COLUMN_NAME)
{
try
{
return dt.Rows[ROW][COLUMN_NAME].ToString();
}
catch (Exception err)
{
MessageBox.Show(err.Message);
return "";

}
}

// function to bring selected results based on column index and row index
public string Results(int ROW, int COLUMN_NAME)
{
try
{
return dt.Rows[ROW][COLUMN_NAME].ToString();
}
catch (Exception err)
{
MessageBox.Show(err.Message);
return dt.Rows[ROW][COLUMN_NAME].ToString();

}
}

// Execute select statement


public void ExecuteSelect(string Sql_command)
{
RecordSource = Sql_command;
ConnectionType = Table;

dt = new DataTable(ConnectionType);
try
{
string command = RecordSource.ToUpper();
MySqlDataAdapter da = new MySqlDataAdapter(RecordSource, connection);
ds = new DataSet();
da.Fill(ds, ConnectionType);
da.Fill(dt);
tempdata = new DataGridView();
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}

// count Number of rows after select


public int Count()
{
return dt.Rows.Count;
}
}

Q. Write a c# program to deign window from that includes-list box, checked list box and radio button

A. using System.Drawing;

using System.Windows.Forms.VisualStyles;

namespace System.Windows.Forms

public class RadioListBox : ListBox

private StringFormat Align;

private bool IsTransparent = false;

private Brush BackBrush;

public override Color BackColor ...


[Browsable(false)]

public override DrawMode DrawMode ...

[Browsable(false)]

public override SelectionMode SelectionMode ...

public RadioListBox() ...

protected override void OnDrawItem(DrawItemEventArgs e) ...

protected override void DefWndProc(ref Message m) ...

protected override void OnHandleCreated(EventArgs e) ...

protected override void OnFontChanged(EventArgs e) ...

protected override void OnParentChanged(EventArgs e) ...

protected override void OnParentBackColorChanged(EventArgs e) ...

// Main painting method

protected override void OnDrawItem(DrawItemEventArgs e)

int maxItem = this.Items.Count - 1;

if (e.Index < 0 || e.Index > maxItem)

e.Graphics.FillRectangle(BackBrush, this.ClientRectangle);

return;
}

int size = e.Font.Height;

Rectangle backRect = e.Bounds;

if (e.Index == maxItem)

backRect.Height = this.ClientRectangle.Top +

this.ClientRectangle.Height - e.Bounds.Top;

e.Graphics.FillRectangle(BackBrush, backRect);

Brush textBrush;

bool isChecked = (e.State & DrawItemState.Selected) == DrawItemState.Selected;

RadioButtonState state = isChecked ?

RadioButtonState.CheckedNormal : RadioButtonState.UncheckedNormal;

if ((e.State & DrawItemState.Disabled) == DrawItemState.Disabled)

textBrush = SystemBrushes.GrayText;

state = isChecked ? RadioButtonState.CheckedDisabled :

RadioButtonState.UncheckedDisabled;

else if ((e.State & DrawItemState.Grayed) == DrawItemState.Grayed)

textBrush = SystemBrushes.GrayText;

state = isChecked ? RadioButtonState.CheckedDisabled :

RadioButtonState.UncheckedDisabled;

else

textBrush = SystemBrushes.FromSystemColor(this.ForeColor);
}

Size glyphSize = RadioButtonRenderer.GetGlyphSize(e.Graphics, state);

Point glyphLocation = e.Bounds.Location;

glyphLocation.Y += (e.Bounds.Height - glyphSize.Height) / 2;

Rectangle bounds = new Rectangle(e.Bounds.X + glyphSize.Width, e.Bounds.Y,

e.Bounds.Width - glyphSize.Width, e.Bounds.Height);

RadioButtonRenderer.DrawRadioButton(e.Graphics, glyphLocation, state);

if (!string.IsNullOrEmpty(DisplayMember))

e.Graphics.DrawString(((System.Data.DataRowView)this.Items[e.Index])

[this.DisplayMember].ToString(),

e.Font, textBrush, bounds, this.Align);

else

e.Graphics.DrawString(this.Items[e.Index].ToString(),

e.Font, textBrush, bounds, this.Align);

e.DrawFocusRectangle();

Q. Write a c# program to design a form that include data grind view control

A. private void Form1_Load(object sender, EventArgs e)

this.vendorTableAdapter.Fill(this.vendorDataSet.Vendor);

Q. Write a c# program on bad format remaining program


Q. Write a c# program on divide by zero error
Q. Write a c# program to check age is valid for driving license or not

Q. Write a c# program on can multiple catch blocks be executed?

You might also like