为什么连接不到数据库
我做啦一个数据库 Text 在windows 应用程序下 通过用户界面 进行添加, 删除 不知道哪里出啦问题
总是连接不到数据库 郁闷
帮我看看
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private SqlConnection myConnection;
private SqlCommand myCommand;
private void Form1_Load(object sender, EventArgs e)
{
myConnection = new SqlConnection ("data source=(.);Initial Catalog=Text;Integrated Security=SSPI ");
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
myConnection.Open();
string sql = "insert into Passenger_table values('" + this.textBox1.Text + " ','" + this.textBox2.Text + " ','" + this.textBox3.Text + " ','" + this.textBox4.Text + "','" + this.textBox5.Text + "')";
myCommand = new SqlCommand(sql, myConnection);
myCommand.ExecuteNonQuery();
MessageBox.Show("插入成功");
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
myConnection.Close();
}
}
private void button3_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
try
{
myConnection.Open();
myCommand = new SqlCommand("delect * from Passenger_table where flightID='" + textBox1 + "'", myConnection);
myCommand.ExecuteNonQuery();
MessageBox.Show("删除成功");
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
myConnection.Close();
}
}
}
}