Using Newproform
Using Newproform
Using Newproform
studentclass;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace newproform
{
public partial class FORMProject : Form
{
public FORMProject()
{
InitializeComponent();
}
}
private void FORMProject_Load(object sender, EventArgs e)
{
DataTable dt = c.Select();
dataGridView1.DataSource = dt;
}
{
MessageBox.Show("update successfuly");
DataTable dt = c.Select();
dataGridView1.DataSource = dt;
clear();
}
else
{
MessageBox.Show("not updated");
}
}
else
{
MessageBox.Show("try again");
}
// load data on grid
DataTable dt = c.Select();
dataGridView1.DataSource = dt;
}
}
}
appconfig
<connectionStrings>
<add name="connstrng" connectionString="Data Source=DESKTOP-CVV11TL\
SQLEXPRESS;Initial Catalog=student;Integrated Security=True"/>;
</connectionStrings>
</configuration>
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace newproform.studemtclass
{
internal class studentclass
{
}
catch (Exception ex)
{
}
finally
{
conn.Close();
}
return dt;
}
public bool Insert(studentclass c)
{
bool isSuccess = false;
conn.Open();
int rows = cmd.ExecuteNonQuery();
if (rows > 0)
{
isSuccess = true;
}
else
{
isSuccess = false;
}
}
catch (Exception ex)
{
}
finally
{
conn.Close();
}
return isSuccess;
cmd.Parameters.AddWithValue("@Name", c.Name);
cmd.Parameters.AddWithValue("@RegNo", c.RegNo);
cmd.Parameters.AddWithValue("@Address", c.Address);
cmd.Parameters.AddWithValue("@Gender", c.Gender);
conn.Open();
if (rows > 0)
{
isSuccess = true;
}
else
{
isSuccess = false;
}
}
catch (Exception eX)
{
}
finally
{
conn.Close();
}
return isSuccess;
}
public bool Delete(studentclass c)
{
bool isSuccess = false;
SqlConnection conn = new SqlConnection(myconnstrng);
try
{
string sql = "Delete from stdtblform Where RegNo=@RegNo";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@RegNo", c.RegNo);
conn.Open();
int rows = cmd.ExecuteNonQuery();
if (rows > 0)
{
isSuccess = true;
}
else
{
isSuccess = false;
}
}
}
finally
{
conn.Close();
}
return isSuccess;
}
}
}