فکر کنم تیتر کامل باشه
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace sandogh
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnInsert_Click(object sender, EventArgs e)
{
try
{
SqlConnection ObjConnect = new SqlConnection("Data Source=ST72;Initial Catalog=sandogh;Integrated Security=True");
SqlCommand ObjCommand = new SqlCommand();
string Str = string.Format("Insert InTo Tbl_sandogh(Fname,Lname,Mablagh,Shomare)values('{0}','{1}',{2},{3})", txtInsertFname.Text, txtInsertLname.Text, txtInsertMablagh.Text, txtInsertShomare.Text);
ObjCommand.Connection = ObjConnect;
ObjCommand.CommandText = Str;
ObjConnect.Open();
ObjCommand.ExecuteNonQuery();
ObjConnect.Close();
MessageBox.Show("Insert InTO ...");
txtInsertFname.Text = "";
txtInsertLname.Text = "";
txtInsertMablagh.Text = "";
txtInsertShomare.Text = "";
}
catch (SqlException ecp)
{
MessageBox.Show(ecp.Message);
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
try
{
SqlConnection ObjConnect = new SqlConnection("Data Source=ST72;Initial Catalog=sandogh;Integrated Security=True");
SqlCommand ObjCommand = new SqlCommand();
string Str = string.Format("Delete From Tbl_sandogh Where Shomare={0}", txtDeleteShomare.Text);
ObjCommand.CommandText = Str;
ObjCommand.Connection = ObjConnect;
ObjConnect.Open();
ObjCommand.ExecuteNonQuery();
ObjConnect.Close();
MessageBox.Show("Delete From ...");
txtDeleteShomare.Text = "";
}
catch (SqlException ecp)
{
MessageBox.Show(ecp.Message);
}
}
private void btnShow_Click(object sender, EventArgs e)
{
SqlConnection ObjConnect = new SqlConnection("Data Source=ST72;Initial Catalog=sandogh;Integrated Security=True");
SqlCommand ObjCommand = new SqlCommand();
string Str = string.Format("Select * From Tbl_sandogh");
SqlDataAdapter Kamun = new SqlDataAdapter();
DataTable Siloo = new DataTable();
ObjCommand.Connection = ObjConnect;
ObjCommand.CommandText = Str;
Kamun.SelectCommand = ObjCommand;
ObjConnect.Open();
ObjCommand.ExecuteNonQuery();
Kamun.Fill(Siloo);
ObjConnect.Close();
dataGridView_Show.Show(Siloo);
dataGridView_Show.Update();
}
}
}
پروژه رو براتون در پایین گذاشتم:
ProjectSandogh
سوالی بود ،بفرمایین
بااحترام
===============================================
اینم مثل بالاییه منتها یک سری چیزای دیگه اضافه داره ، خیلی میتونه کمک کنه
امیدوارم مفید فایده باشه
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace ST
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection ObjConnect = new SqlConnection("Data Source=RASTIN-PC;Initial Catalog=Student;Integrated Security=True");
SqlCommand ObjCommand = new SqlCommand();
string str = string.Format("Insert InTo Tbl_Student (Fname,Lname,Idname) Values ('{0}','{1}',{2})", textBox1.Text, textBox2.Text, textBox3.Text);
ObjCommand.CommandText = str;
ObjCommand.Connection = ObjConnect;
ObjConnect.Open();
ObjCommand.ExecuteNonQuery();
ObjConnect.Close();
MessageBox.Show("OK");
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
catch (SqlException ecp)
{
MessageBox.Show(ecp.Message);
}
}
private void btn_Delete_Click(object sender, EventArgs e)
{
try
{
SqlConnection ObjConnect = new SqlConnection("Data Source=RASTIN-PC;Initial Catalog=Student;Integrated Security=True");
SqlCommand ObjCommand = new SqlCommand();
string str = string.Format("Delete From Tbl_Student Where Idname={0}", textBox3.Text);
ObjCommand.CommandText = str;
ObjCommand.Connection = ObjConnect;
ObjConnect.Open();
ObjCommand.ExecuteNonQuery();
ObjConnect.Close();
MessageBox.Show("OK");
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
catch(SqlException ecp)
{
MessageBox.Show(ecp.Message);
}
}
private void btn_Update_Click(object sender, EventArgs e)
{
try
{
SqlConnection ObjConnect = new SqlConnection("Data Source=RASTIN-PC;Initial Catalog=Student;Integrated Security=True");
SqlCommand ObjCommand = new SqlCommand();
SqlDataAdapter Kamun = new SqlDataAdapter();
DataTable Siloo = new DataTable();
string str = string.Format("Update Tbl_Student Set Fname,Lname Where Idname = {0}",textBox3.Text);
ObjCommand.CommandText = str;
ObjCommand.Connection = ObjConnect;
Kamun.SelectCommand = ObjCommand;
ObjConnect.Open();
ObjCommand.ExecuteNonQuery();
Kamun.Fill(Siloo);
ObjConnect.Close();
dataGridView1.Show();
dataGridView1.Update();
MessageBox.Show("OK");
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
catch(SqlException ecp)
{
MessageBox.Show(ecp.Message);
}
}
private void btn_Select_Click(object sender, EventArgs e)
{
try
{
SqlConnection ObjConnect = new SqlConnection("Data Source=RASTIN-PC;Initial Catalog=Student;Integrated Security=True");
SqlCommand ObjCommand = new SqlCommand();
SqlDataAdapter Kamun = new SqlDataAdapter();
DataTable Siloo = new DataTable();
string str = string.Format("Select * From Tbl_Student");
ObjCommand.CommandText = str;
ObjCommand.Connection = ObjConnect;
Kamun.SelectCommand = ObjCommand;
ObjConnect.Open();
ObjCommand.ExecuteNonQuery();
Kamun.Fill(Siloo);
ObjConnect.Close();
dataGridView1.Show();
dataGridView1.Update();
//MessageBox.Show("OK");
//textBox1.Text = "";
//textBox2.Text = "";
//textBox3.Text = "";
}
catch (SqlException ecp)
{
MessageBox.Show(ecp.Message);
}
}
}
}
موفق باشین
بااحترام موضوعات مشابه:
علاقه مندی ها (Bookmarks)