C#建立数据库,一直建立失败,请帮忙看看。 5
DataSetds=newDataSet();stringconsqlserve="DataSource=GM-PC\\SQLEXPRESS;InitialCatalog...
DataSet ds = new DataSet();
string consqlserve = "Data Source=GM-PC\\SQLEXPRESS;Initial Catalog=;Integrated Security=True";
SqlConnection con = new SqlConnection(consqlserve);
try
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "CREATE DATABASE" + textBox1.Text;
cmd.Connection = con;
cmd.ExecuteNonQuery();
MessageBox.Show("创建成功", "信息提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("创建失败", "信息提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
}
执行到cmd.ExecuteNonQuery();就会出现异常。 展开
string consqlserve = "Data Source=GM-PC\\SQLEXPRESS;Initial Catalog=;Integrated Security=True";
SqlConnection con = new SqlConnection(consqlserve);
try
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "CREATE DATABASE" + textBox1.Text;
cmd.Connection = con;
cmd.ExecuteNonQuery();
MessageBox.Show("创建成功", "信息提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("创建失败", "信息提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
}
执行到cmd.ExecuteNonQuery();就会出现异常。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询