using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlConnection sqlcon = new SqlConnection("Data Source= (local);DataBase = Theatre_MS;uid =sa;pwd = 123;");
            try
            {
                sqlcon.Open();//数据库需要打开
                string sqlstr = "insert into User_TB values('1','2','1');";
                SqlCommand cmd = new SqlCommand(sqlstr,sqlcon);//须记住cmd的new时需要两个参数,一个是sqlstr,一个是数据库连接---->用来表明是对那个数据库进行那种操作
                cmd.ExecuteNonQuery();//executeNonQuery返回是得影响的行数
                Console.WriteLine("Yes!");


            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.Message);//输出得是ex。Message

            }
            Console.ReadLine();

        }
    }
}


 

相关文章:

  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2022-02-17
  • 2021-09-06
  • 2021-12-01
  • 2022-12-23
猜你喜欢
  • 2021-12-18
  • 2021-11-24
  • 2022-12-23
  • 2021-11-16
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案