注册 登录
编程论坛 C# 论坛

c#代码出错

lukebc 发布于 2016-08-27 21:52, 2361 次点击
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication9
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "server=USER-20160806SI\\SQLEXPRESS;uid=sa;pwd=sa database=luke";
            conn.Open();
            DataTable dt = new DataTable("resouce");
            dt.Clear();
            string sql = "insert into text1 values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
            SqlCommand command = new SqlCommand(sql, conn);
            SqlDataAdapter ad = new SqlDataAdapter();
            ad.SelectCommand = command;
            ad.Fill(dt);
            dt.Clear();
            SqlDataAdapter adp=new SqlDataAdapter("select * from text1",conn);
            adp.Fill(dt);
            dataGridView1.DataSource=dt.DefaultView;
        }
    }
}

只有本站会员才能查看附件,请 登录
  提示sa登陆失败,但是我的其它代码这么连接都没问题啊,不知错在哪里
2 回复
#2
不说也罢2016-08-28 07:49
pwd=sa;
是不是少了这个小分号?
#3
lukebc2016-08-28 09:25
回复 2楼 不说也罢
谢谢
1