imwjb 你太有才了.. 哈哈哈哈....

解决方案 »

  1.   

    太牛了,我真的不得不佩服你啊imwjb,你简直就是可以当作家了
    够牛,顶一下
      

  2.   

    SqlTransaction stran = con.BeginTransaction();
                    cmd.Transaction = stran;
                    try
                    {
    con.Open();                    int count= cmd.ExecuteNonQuery();
                        stran.Commit();
                    }
                    catch
                    {
                        con.Close();
                    }
      

  3.   

    问题呢?是不是这样,我修改过的东西在句子后加上“///”?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;    //sql数据库用这个///
    namespace Demo1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button3_Click(object sender, EventArgs e)
            {
               
            }        private void button1_Click(object sender, EventArgs e)
            {
                SqlConnection con = new SqlConnection("Server=localhost;Integrated Security=SSPI;database=NorthWind");            String sql = "insert into Student (Stu_ID,Stu_Name,Stu_Sex,Stu_Address,Stu_Phone) valuse(@id,@name,@sex,@address,@phone)";
                SqlCommand cmd = new SqlCommand(sql,con);            cmd.Parameters.Add("@id", SqlDbType.VarChar, 20);///
                cmd.Parameters.Add("@name",SqlDbType.VarChar,20);
                cmd.Parameters.Add("@sex",SqlDbType.VarChar,10);
                cmd.Parameters.Add("@address",SqlDbType.VarChar,50);
                cmd.Parameters.Add("@phone",SqlDbType.VarChar,24);            cmd.Parameters[0].Value = this.sid.Text.ToString();///
                cmd.Parameters[1].Value = this.sname.Text.ToString();///
                cmd.Parameters[2].Value = this.ssex.Text.ToString();///
                cmd.Parameters[3].Value = this.saddress.Text.ToString();///
                cmd.Parameters[4].Value = this.sphone.Text.ToString();///            try
                {
                    con.Open();
                    int count = cmd.ExecuteNonQuery();//执行insert delete update ,返回受影响的行数
                    if (count == 1)
                    {
                        MessageBox.Show("插入成功!");
                    }
                }
                catch
                {
                }
                finally
                {
                    con.Close();
                }        }
        }
    }
      

  4.   

    SqlConnection con = new SqlConnection("Server=localhost;Integrated Security=SSPI;database=NorthWind");
    if (con.State != ConnectionState.Open)
    {
                    con.Open();
    }
      

  5.   

    insert into Student (Stu_ID,Stu_Name,Stu_Sex,Stu_Address,Stu_Phone) valuse(@id,@name,@sex,@address,@phone)
    这个语句也不对
    valuse改values
      

  6.   

    imwjb不要到处发这段东西了,我今早都看了很多遍-_-#!