我正在尝试使用.net连接到SQL EXPRESS数据库。我也得到错误无法打开数据库" binarystream"登录请求。登录失败。
但我的dataconnect已显示我已连接到databaseenter
这是我的C#代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection dee= new SqlConnection("Data Source=(local)\SQLEXPRESS;Initial Catalog=binarystream;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter();
da.InsertCommand = new SqlCommand("INSERT INTO CUSTOMER VALUES(@USERNAME,@PASSWORD)",dee);
da.InsertCommand.Parameters.Add("@username", SqlDbType.VarChar).Value = textBox1;
da.InsertCommand.Parameters.Add("@password", SqlDbType.VarChar).Value = textBox2;
dee.Open();
da.InsertCommand.ExecuteNonQuery();
dee.Close();
}
}
}