این کد رو امتحان کن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 sql
{
public partial class Form1 : Form
{ bool t1, t2;
SqlCommand cmd;
SqlConnection cnn;
SqlDataAdapter da;
DataSet dset;
public Form1()
{
InitializeComponent();
//***************************** set connection************
cnn =new SqlConnection();
cnn.ConnectionString = ("integrated security=SSPI;persist security info=True;initial catalog=me");
}
private void button1_Click(object sender, EventArgs e)
{
{
try
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = cnn;
cmd.CommandText = "INSERT INTO table1 (first2, last2)" +
"VALUES(@first2, @last2)";
cmd.Parameters.AddWithValue("@last2", textBox1.Text);
cmd.Parameters.AddWithValue("@first2", textBox2.Text);
cnn.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("record inserted Successfully");
cnn.Close();
}
catch (SqlException e1)
{
cnn.Close();
MessageBox.Show(e1.ToString());
}
}
}