如何解决设计器中未处理的异常
我在 Visual Studio 2019 中创建了一个项目,该项目在名为 Home
的表单中有多个用户控件。
一切顺利,直到今天。重建我的项目后 Home
表单显示错误提示
The control system.windows.forms.form has thrown an unhandled exception in the designer and has been desabled.
Exception :
An attempt to attach an auto-named database for file c:\program files(x86)\Microsoft Visual Studio\2019\Enterprise\common7\ide\database\pharmacy.mdf Failed. A database with the same name exists,or specified file cannot be opened,or it is located on unc share.
代码:
sqlConnection con = new sqlConnection(@"Data Source=LocalDB)\MSsqlLocalDB;AttachDbFilename=D:\Final Project BCA\PharmacyManagementSystemCSharp\Database\pharmacy.mdf;Integrated Security=True");
con.open()
String str = "Select max(id) from supp;";
sqlCommand cmd = new sqlCommand(str,con);
sqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
String val = dr[0].ToString();
if (val == "")
{
.....
}
private void button1_Click(object sender,EventArgs e)
{
sqlConnection con = new sqlConnection(@"Data Source= (LocalDB)\MSsqlLocalDB;AttachDbFilename=D:\Final Project BCA\PharmacyManagementSystemCSharp\Database\pharmacy.mdf;Integrated Security=True");
con.open();
try
{
String str = "Insert into supp(name,email,mobile,addr,s_code) values('" + Sup_Name.Text + "','" + Sup_Email.Text + "','" + Sup_Mobile.Text + "','" + Sup_Add.Text + "','" + Sup_Code.Text + "');";
sqlCommand cmd = new sqlCommand(str,con);
cmd.ExecuteNonQuery();
String str1 = "select max(ID) from supp;";
sqlCommand cmd1 = new sqlCommand(str1,con);
sqlDataReader dr = cmd1.ExecuteReader();
if (dr.Read())
{
MessageBox.Show("Inserted supplier Data SuccessFully..");
using (sqlConnection con1 = new sqlConnection(@"Data Source=(LocalDB)\MSsqlLocalDB;AttachDbFilename=D:\Final Project BCA\PharmacyManagementSystemCSharp\Database\pharmacy.mdf;Integrated Security=True"))
{
String str2 = "Select * from supp";
sqlCommand cmd2 = new sqlCommand(str2,con1);
sqlDataAdapter sda = new sqlDataAdapter(cmd2);
DataTable dt = new DataTable();
sda.Fill(dt);
supplierDataGV.DataSource = new BindingSource(dt,null);
}
Sup_Name.Text = "";
Sup_Code.Text = "";
Sup_Email.Text = "";
Sup_Mobile.Text = "";
Sup_Add.Text = "";
}
}
catch (sqlException ex)
{
MessageBox.Show(ex.Message);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。