我的某个程序有点问题。在这个我已经在SQL中创建了一个关于不同油漆的卖家和买家的数据库(颜色如绿色,红色等)。然后,当数据库完成后,我在C#中创建了一个客户端应用程序并将其连接到数据库。数据库中的每个表(名称为Fakturace - Billing,Bill)我能够在我的form2中的dataGrid上打印。麻烦开始了 - 当我尝试添加卖方或买方的另一个Reord或Bill或Paint时,有一个异常会不断出现。它包含在图片中。
代码是:`
int id_kup;
int id_barva;
int id_faktura;
string jm;
string prijm;
string tel_cisl;
int cislo_uctu;
string alias;
int ičo;
int dič;
string adresa;
int kod;
string naz_bar;
string znacka;
string typ;
int dph;
double jedn_cena;
double mnozstvi;
string dat_splat;
string dat_vyst;
string datum_plneni;
int var_sym;
int konst_symb;
int id_prod1;
int id_kup1;
private void Form2_Load(object sender, EventArgs e)
{
textBox1.Visible = false;
textBox2.Visible = false;
textBox3.Visible = false;
textBox4.Visible = false;
textBox5.Visible = false;
textBox6.Visible = false;
textBox7.Visible = false;
textBox8.Visible = false;
textBox9.Visible = false;
button14.Visible = false;
}
private void button1_Click(object sender, EventArgs e)
{
DBVrstva d1 = new DBVrstva();
d1.nacti_prodejce(dataGridView1);
}
private void button4_Click(object sender, EventArgs e)
{
DBVrstva d4 = new DBVrstva();
d4.nacti_kupujícího(dataGridView2);
}
private void button7_Click(object sender, EventArgs e)
{
DBVrstva d7 = new DBVrstva();
d7.nacti_barvu(dataGridView3);
}
private void button13_Click(object sender, EventArgs e)
{
DBVrstva d13 = new DBVrstva();
d13.nacti_fakturu(dataGridView4);
}
private void button2_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(textBox1.Text);
jm = textBox2.Text;
prijm = textBox3.Text;
tel_cisl = textBox4.Text;
cislo_uctu = Convert.ToInt32(textBox5.Text);
alias = textBox6.Text;
ičo = Convert.ToInt32(textBox7.Text);
dič = Convert.ToInt32(textBox8.Text);
adresa = textBox9.Text;
textBox1.Visible = true;
textBox2.Visible = true;
textBox3.Visible = true;
textBox4.Visible = true;
textBox5.Visible = true;
textBox6.Visible = true;
textBox7.Visible = true;
textBox8.Visible = true;
textBox9.Visible = true;
button14.Visible = true;
try
{
String Cstr = @"server= BLACK-TOSHIBA\SQLEXPRESS;database = Fakturace;UID=sa;PWD=f10dr0v1c";
string ctext = "insert into Prodejce(id_prod,jm,prijm,tel_cisl,cislo_uctu, alias, ičo,dič,adresa) values('" + id + "','" + jm + "','" + prijm + "','" + tel_cisl + "','" + cislo_uctu + "','" + alias + "','" + ičo + "','" + dič + "','" + adresa + "')";
DBVrstva da = new DBVrstva();
da.Transakce(ctext, Cstr);
}
catch (Exception)
{
MessageBox.Show("Zadal jsi něco špatně");
}
}
private void button10_Click(object sender, EventArgs e)
{
MessageBox.Show(" Ukončujete aplikaci! ");
Application.Exit();
}
private void button3_Click(object sender, EventArgs e)
{
//odebrat prodavajiciho
}
private void button5_Click(object sender, EventArgs e)
{
//pridat kupujiciho
id_kup = Convert.ToInt32(textBox1.Text);
jm = textBox2.Text;
prijm = textBox3.Text;
tel_cisl = textBox4.Text;
cislo_uctu = Convert.ToInt32(textBox5.Text);
alias = textBox6.Text;
ičo = Convert.ToInt32(textBox7.Text);
dič = Convert.ToInt32(textBox8.Text);
adresa = textBox9.Text;
textBox1.Visible = true;
textBox2.Visible = true;
textBox3.Visible = true;
textBox4.Visible = true;
textBox5.Visible = true;
textBox6.Visible = true;
textBox7.Visible = true;
textBox8.Visible = true;
textBox9.Visible = true;
button14.Visible = true;
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
try
{
String Cstr = @"server= BLACK-TOSHIBA\SQLEXPRESS;database = Fakturace;UID=sa;PWD=f10dr0v1c";
string ctext = "insert into Kupující(id_kup,jm,prijm,tel_cisl,cislo_uctu, alias, ičo,dič,adresa) values('" + id_kup + "','" + jm + "','" + prijm + "','" + tel_cisl + "','" + cislo_uctu + "','" + alias + "','" + ičo + "','" + dič + "','" + adresa + "')";
DBVrstva da = new DBVrstva();
da.Transakce(ctext, Cstr);
}
catch (Exception)
{
MessageBox.Show("Zadal jsi něco špatně");
}
}
private void button6_Click(object sender, EventArgs e)
{
//odebrat prodavajiciho
}
private void button8_Click(object sender, EventArgs e)
{
//pridat barvu
textBox1.Visible = true;
textBox2.Visible = true;
textBox3.Visible = true;
textBox4.Visible = true;
textBox5.Visible = true;
textBox6.Visible = true;
textBox7.Visible = true;
textBox8.Visible = true;
id_barva = Convert.ToInt32(textBox1.Text);
kod = Convert.ToInt32(textBox2.Text);
naz_bar = textBox3.Text;
znacka = textBox4.Text;
typ = textBox5.Text;
dph = Convert.ToInt32(textBox6.Text);
jedn_cena = Convert.ToDouble(textBox7.Text);
mnozstvi = Convert.ToDouble(textBox8.Text);
try
{
String Cstr = @"server= BLACK-TOSHIBA\SQLEXPRESS;database = Fakturace;UID=sa;PWD=f10dr0v1c";
string ctext = "insert into Barva(id_barva, kod, naz_bar,znacka, typ, dph, jedn_cena, mnozstvi) values('" + id_barva + "','" + kod + "','" + naz_bar + "','" + znacka + "','" + typ + "','" + dph + "','" + jedn_cena + "','" + mnozstvi + "')";
DBVrstva da = new DBVrstva();
da.Transakce(ctext, Cstr);
}
catch (Exception)
{
MessageBox.Show("Zadal jsi něco špatně");
}
}
private void button9_Click(object sender, EventArgs e)
{
//odebrat barvu
}
private void button12_Click(object sender, EventArgs e)
{
//pridat fakturu
textBox1.Visible = true;
textBox2.Visible = true;
textBox3.Visible = true;
textBox4.Visible = true;
textBox5.Visible = true;
textBox6.Visible = true;
textBox7.Visible = true;
textBox8.Visible = true;
textBox9.Visible = true;
id_faktura = Convert.ToInt32(textBox1.Text);
dat_splat = textBox2.Text;
dat_vyst = textBox3.Text;
datum_plneni = textBox4.Text;
var_sym = Convert.ToInt32(textBox5.Text);
konst_symb = Convert.ToInt32(textBox6.Text);
id_prod1 = Convert.ToInt32(textBox7.Text);
id_kup1 = Convert.ToInt32(textBox8.Text);
int id_bar1 = Convert.ToInt32(textBox9.Text);
try
{
String Cstr = @"server= BLACK-TOSHIBA\SQLEXPRESS;database = Fakturace;UID=sa;PWD=f10dr0v1c";
string ctext = "insert into Faktura(id_faktura,dat_splat,dat_vyst,datum_plneni,var_sym,konst_symb,id_prod1,id_kup1,id_bar1) values('" + id_faktura + "','" + dat_splat + "','" + dat_vyst + "','" + datum_plneni + "','" + var_sym + "','" + konst_symb + "','" + id_prod1 + "','" + id_kup1 + "','" + id_bar1 + "',' )";
DBVrstva da = new DBVrstva();
da.Transakce(ctext, Cstr);
}
catch (Exception)
{
MessageBox.Show("Zadal jsi něco špatně");
}
}
private void button11_Click(object sender, EventArgs e)
{
//odebrat fakturu
}
}
`
请注意,这只是Form2的代码 - 还有用于登录应用程序的表单1和名为DBVrstava的类,我用它来支持与数据库和SQL服务器的连接。