مرسی از شما اما من بستم مثلا یک فرم که می یاد بیرون اینه ببینید
using System;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace courseselection
{
public partial class frmadostad : Form
{
//string str = "Data Source=DASHI-77A4AECA0\\SQLEXPRESS;Initial Catalog=farhang;Integrated Security=True";
SqlDataAdapter objDataAdapter;
CurrencyManager objcurrencymanager;
DataView objDataView;
public frmadostad()
{
SqlConnection objconnection = connectionclass.getconnection ();
objDataAdapter = new SqlDataAdapter("SELECT * FROM teacher", objconnection);
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void label5_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection objConnection = connectionclass .getconnection ();
SqlCommand objCommand = new SqlCommand();
objCommand.Connection = objConnection;
objCommand.CommandText = "INSERT INTO teacher" +
"(tcode, tname, tfamily, tid,tmarrid,tfieldstudy,tdegree,tsex) " +
"VALUES(@tcode, @tname, @tfamily, @tid,@tmarrid,@tfieldstudy,@tdegree,@tsex)";
if (textBox1.Text.Length > 5)
{
objCommand.Parameters.AddWithValue("@tcode", textBox1.Text);
objCommand.Parameters.AddWithValue("@tname", textBox2.Text);
objCommand.Parameters.AddWithValue("@tfamily", textBox3.Text);
objCommand.Parameters.AddWithValue("@tid", textBox4.Text);
objCommand.Parameters.AddWithValue("@tmarrid", textBox5.Text);
objCommand.Parameters.AddWithValue("@tfieldstudy", textBox6.Text);
objCommand.Parameters.AddWithValue("@tdegree", textBox7.Text);
if (radioButton1.Checked == false && radioButton2.Checked == false)
objCommand.Parameters.AddWithValue("@tsex", "نامشخص");
if (radioButton1.Checked == true)
objCommand.Parameters.AddWithValue("@tsex", radioButton1.Text);
if (radioButton2.Checked == true)
objCommand.Parameters.AddWithValue("@tsex", radioButton2.Text);
objConnection.Open();
try
{
objCommand.ExecuteNonQuery();
MessageBox.Show(".ثبت با موفقیت انجام شد", "تعریف استاد", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch
{
MessageBox.Show("!کداستاد تکراری است", "هشدار", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
objConnection.Close();
}
else
{
MessageBox.Show("کداستاد حداقل 6 کاراکتر لازم دارد", "هشدار", MessageBoxButtons.OK, MessageBoxIcon.Warning );
textBox1.Text = "";
textBox1.Focus();
}
}
private void button4_Click (object sender, EventArgs e)
{
Application.OpenForms[0].Show( );
}
}
}