|
-
Oct 15th, 2020, 03:42 AM
#1
Thread Starter
New Member
failed to enable constrains.One or more rows contain value violating non-null,unique,
Hi Everyone:
I am trying to print my voucher data but its giving above mentioned error.I am very new in this field and tried several time to solved but failed.If any one can help me i will be thankful. Here is my code:
Code:
Try
Cursor = Cursors.WaitCursor
Timer1.Enabled = True
Dim rpt As New rptVoucher
Dim myConnection As SqlConnection
Dim MyCommand As New SqlCommand()
Dim myDA As New SqlDataAdapter()
Dim myDS As New DataSet3
myConnection = New SqlConnection(cs)
MyCommand.Connection = myConnection
MyCommand.CommandText = "SELECT Pettycash.ID, Pettycash.Pettycashno,Pettycash.Date, Pettycash.Accountno, Pettycash.Accountname, Pettycash.Amount, Pettycash_Details.VD_ID,Pettycash_Details.Accountname, Pettycash_Details.AccountNo, Pettycash_Details.Billref, Pettycash_Details.Narration, Pettycash_Details.Amount FROM Pettycash INNER JOIN Pettycash_Details ON Pettycash.ID = Pettycash_Details.VoucherID where Pettycashno='" & txtVoucherNo.Text & "'"
MyCommand.CommandType = CommandType.Text
myDA.SelectCommand = MyCommand
myDA.Fill(myDS, "Pettycash")
myDA.Fill(myDS, "Pettycash_Details")
rpt.SetDataSource(myDS)
frmReport.CrystalReportViewer1.ReportSource = rpt
frmReport.ShowDialog()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

-
Oct 15th, 2020, 03:48 AM
#2
Re: failed to enable constrains.One or more rows contain value violating non-null,uni
As I commented on Stack Overflow, why are you executing the same query twice to populate two different DataTables? Either you want all the data in one DataTable, in which case you execute the query once, or you want it in two DataTables, in which case you execute two different queries with no join.
-
Oct 15th, 2020, 03:51 AM
#3
Re: failed to enable constrains.One or more rows contain value violating non-null,uni
Also, what's up with this:
Code:
Dim myDS As New DataSet3
What is a DataSet3 is that a typed DataSet? If so, why are you creating all your own ADO.NET objects instead of using table adapters?
-
Oct 15th, 2020, 03:57 AM
#4
Thread Starter
New Member
Re: failed to enable constrains.One or more rows contain value violating non-null,uni
 Originally Posted by jmcilhinney
Also, what's up with this:
Code:
Dim myDS As New DataSet3
What is a DataSet3 is that a typed DataSet? If so, why are you creating all your own ADO.NET objects instead of using table adapters?
Hi Sir,
Yes DataSet3 is my DataSet
-
Oct 15th, 2020, 04:03 AM
#5
Thread Starter
New Member
Re: failed to enable constrains.One or more rows contain value violating non-null,uni
 Originally Posted by jmcilhinney
As I commented on Stack Overflow, why are you executing the same query twice to populate two different DataTables? Either you want all the data in one DataTable, in which case you execute the query once, or you want it in two DataTables, in which case you execute two different queries with no join.
Hi Sir,
Actually i want it to in Two DataTables but i don't know how to execute two different queries with no join.Please help me out sir.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|