本文介绍了我的应用程序中的异常和错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已经写了这段代码

SqlConnection con = new SqlConnection("Data Source=MOSTAFA;Initial Catalog=mohasba;Integrated Security=True");

SqlCommand com = new SqlCommand("insert into Ezn_Qaid (Qaid_no,Qaid_date,Maden,Dayn,El_Qema,Qaid_Type,Bayan_Oll) values(''" + B_No.Text + "'',''" + B_Date.Text + "'',''" + B_m.Text + "'',''" + B_D.Text + "'',''" + B_Q.Text + "'',''" + comboBox3.SelectedIndex + "'',''" +comboBox1.SelectedIndex+ "'')", con);
            
con.Open();
com.ExecuteNonQuery();



并获得以下erorr

  INSERT 语句与 FOREIGN  关键字 约束 "  span>  FK__Ezn_Qaid__Bayan ___ 44FF419A".发生冲突 数据库 "  mohasba"表格 "   dbo.Bayan"  '  byan_name" .
该语句已终止.



注意
数据库

create table Ezn_Qaid 
( 
Qaid_no nvarchar(20) , 
Qaid_date nvarchar(10)  , 
Maden float , 
Dayn float, 
El_Qema float,
Qaid_Type nvarchar(15) , 
--byan_name int NOT NULL,   -- this is the new column 
Bayan_Oll nvarchar(100) FOREIGN KEY (Bayan_Oll) REFERENCES Bayan(byan_name ),
Bayan_Bank nvarchar(100) FOREIGN KEY (Bayan_Bank ) REFERENCES Bank(byan_name ),
Bayan_3momya nvarchar(100) FOREIGN KEY (Bayan_3momya) REFERENCES msaref_3momya(byan_name ),
Bayan_Tkalef nvarchar(100) FOREIGN KEY (Bayan_Tkalef) REFERENCES tkalef_nshat (byan_name )
) 


create table Bayan
(
byan_no int identity ,
byan_name nvarchar(100)PRIMARY KEY
)


byan_name列仅包含一个记录"Visa",而组合框项目则包含"Visa"

谢谢

解决方案



Hi
I have wrote this code

SqlConnection con = new SqlConnection("Data Source=MOSTAFA;Initial Catalog=mohasba;Integrated Security=True");

SqlCommand com = new SqlCommand("insert into Ezn_Qaid (Qaid_no,Qaid_date,Maden,Dayn,El_Qema,Qaid_Type,Bayan_Oll) values(''" + B_No.Text + "'',''" + B_Date.Text + "'',''" + B_m.Text + "'',''" + B_D.Text + "'',''" + B_Q.Text + "'',''" + comboBox3.SelectedIndex + "'',''" +comboBox1.SelectedIndex+ "'')", con);
            
con.Open();
com.ExecuteNonQuery();



and get the following erorr

The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Ezn_Qaid__Bayan___44FF419A". The conflict occurred in database "mohasba", table "dbo.Bayan", column 'byan_name'.
The statement has been terminated.



Note
the database

create table Ezn_Qaid 
( 
Qaid_no nvarchar(20) , 
Qaid_date nvarchar(10)  , 
Maden float , 
Dayn float, 
El_Qema float,
Qaid_Type nvarchar(15) , 
--byan_name int NOT NULL,   -- this is the new column 
Bayan_Oll nvarchar(100) FOREIGN KEY (Bayan_Oll) REFERENCES Bayan(byan_name ),
Bayan_Bank nvarchar(100) FOREIGN KEY (Bayan_Bank ) REFERENCES Bank(byan_name ),
Bayan_3momya nvarchar(100) FOREIGN KEY (Bayan_3momya) REFERENCES msaref_3momya(byan_name ),
Bayan_Tkalef nvarchar(100) FOREIGN KEY (Bayan_Tkalef) REFERENCES tkalef_nshat (byan_name )
) 


create table Bayan
(
byan_no int identity ,
byan_name nvarchar(100)PRIMARY KEY
)


The column byan_name contain only one record "Visa" and the combobox item contain "Visa"

Thanks

解决方案




这篇关于我的应用程序中的异常和错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 06:57