Click here to Skip to main content
15,918,303 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
private bool SaveDetails()
{
//validation for textbox not empty
bool Check;
Check = true;
if (txt_Faccode.Text.Trim().Length == 0)
{
Check = false;
MessageBox.Show("Please enter the Faculty code","Not Enter the details",MessageBoxButtons.OK,MessageBoxIcon.Information);
return Check;
}

if (Txt_Facname.Text.Trim().Length == 0)
{
Check = false;
MessageBox.Show("Please enter the Faculty Name","Not Enter the details",MessageBoxButtons.OK,MessageBoxIcon.Information);
return Check;
}

if (txt_Hrs.Text.Trim().Length == 0)
{
Check = false;
MessageBox.Show("Please enter the allocated hours","Not Enter the details",MessageBoxButtons.OK,MessageBoxIcon.Information);
return Check;
}


//insert code for update to the DataBase
this.Cursor = Cursors.WaitCursor;
try
{
sql = "insert into Tb_SCH_Faculty_Details ([Faculty_Code], [Faculty_Name],[Allocated_Hours]) " + " values('" + txt_Faccode.Text + "','" + Txt_Facname.Text + "', " + txt_Hrs.Text + ")";

int temp = 0;
if (!int.TryParse(txt_Hrs.Text.Trim(), out temp))
{
Check = false;
this.Cursor = Cursors.Arrow;
MessageBox.Show("Enter Numbers only in allocated hours", "Characters Not Allowed", MessageBoxButtons.OK, MessageBoxIcon.Error);
return Check;
}

GFun.Error = "";
GFun.InsertAccessData(sql);
if (GFun.Error.ToString() != "")
{
Check = false;
MessageBox.Show(GFun.Error.ToString(), "Error");
this.Cursor = Cursors.Arrow;
return Check;
}

GFun.OleDbCon.Close();
}
catch (Exception ex)
{
Check = false;
MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Cursor = Cursors.Arrow;
return Check;
}
this.Cursor = Cursors.Arrow;
return Check;
}
private void Btn_Save_Click(object sender, EventArgs e)
{
if (SaveDetails() == true)
MessageBox.Show("Record Inserted Successfully", "Records Inserted", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

run mode as follows;

Faculty code textbox
Faculty name textbox
Alloated hrs textbox

when i enter all the details and click the save button, the above three items records should be displayed in datagridview.

for that how can i do using csharp.
Posted

1 solution

Hi i think it will helps you..

note:- this is using MySql Database if there is Sql Server then just replace MySql with Sql using proper NameSpace(Using System.Data.SqlClient;)

C#
//make a connection string
 con.ConnectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
// Opent the connection
            con.Open();
// make object of Mysql command method
            MySqlCommand cmd = new MySqlCommand("select Faculty_Code,Faculty_Name,Allocated_Hours from Tb_SCH_Faculty_Details", con);
// object of MySql Data Adapter
            MySqlDataAdapter da = new MySqlDataAdapter(cmd);
// object of data table
            DataTable dt = new DataTable();
// store the data
            da.Fill(dt);
//finally set the value in grid view control
            datagridview.DataSource = dt;
            datagridview.DataBind();
// close the connection
            con.Close();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900