Parameter count mismatch. on setDataSource - vb.net

I am trying the following and my report contains no parameters also Iam using .Net Objects
Dim data = GetDataConnection()
Dim ds = (From th In data.TranHeads Where th.THCSCode = "YYY001"
Select th).ToList
Dim crySalesTran As ReportDocument = New IBS_DAL.rep_SalesTransaction
crySalesTran.SetDataSource(ds.AsEnumerable)
CrystalReportViewer1.ReportSource = crySalesTran
for some reason when it reaches setdatasource
TargetParameterCountException Parameter count mismatch.

I found the answer although not sure why this works and the other option doesn't
Dim da = New System.Data.SqlClient.SqlDataAdapter("SELECT THSysRef, THCSCode FROM TranHead Where THCSCode = "YYY001" ", data.Connection)
Dim dtTH = New DataTable
da.Fill(dtTH)
Dim crySalesTran As ReportDocument = New IBS_DAL.rep_SalesTransaction
crySalesTran.Database.Tables(0).SetDataSource(dtTH)
CrystalReportViewer1.ReportSource = crySalesTran

Related

Added collection of images from SQL datareader on ItextSharp

I need to get a collection of images from a datareader or even from a datatable (if recommended to use this) of sql.
My intent is to populate the cell with the variable "myimage" (and I succeed perfectly)
In the variable "myimage2" I would like to insert the collection of images obtained from a datareader or a datatable, what can I do?
Currently I can insert only one image using the "getvalue" method as written in the code.
Dim connessione As New SqlConnection
Dim comando As New SqlCommand
connessione.ConnectionString = stringa_database
connessione.Open()
comando = connessione.CreateCommand()
comando.CommandType = CommandType.Text
comando.CommandText = "SELECT u.id_nota, u.immagine From immagini_aggiuntive u INNER JOIN note q ON q.id = id_nota where id_nota= " & id
Dim lettura As SqlDataReader = comando.ExecuteReader()
lettura.Read()
Dim imageByte2 As Byte() = CType(lettura.GetValue(1), Byte())
Dim ms2 As New MemoryStream(imageByte2, 0, imageByte2.Length)
Dim myImage2 As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(ms2)
'fine blocco
Dim imageByte As Byte() = CType(row.Cells(11).Value, Byte())
Dim ms As New MemoryStream(imageByte, 0, imageByte.Length)
Dim myImage As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(ms)
Dim cellimg As PdfPCell = New PdfPCell()
cellimg.AddElement(myImage)
cellimg.AddElement(myImage2)
pdfTable.AddCell(cellimg)
lettura.Close()
connessione.Close()

vb.net: column names using recordset as Odbc.OdbcDataReader

I'm creating a Web Service that retrive data from postgres DB.
Here my code:
Dim sql As String
Dim recordSet As Odbc.OdbcDataReader
Dim command As Odbc.OdbcCommand
Dim ret As New DataOutput
Dim dataLst As New List(Of Data)
Dim element As Dati
sql = "SELECT * from demo.table"
command = New Odbc.OdbcCommand(sql, odbcConn)
Try
recordSet = command.ExecuteReader
While recordSet.Read()
element = New Data
element.id = recordSet(0)
element.name = recordSet(1)
element.description = recordSet(2)
element.address = recordSet(3)
dataLst.Add(element)
End While
ret.arrDati = dataLst
This only show me rows value but I need column names too.
How can i do this?
You can access the column names with the GetName method:
Dim sql As String
Dim recordSet As Odbc.OdbcDataReader
Dim command As Odbc.OdbcCommand
Dim ret As New DataOutput
Dim dataLst As New List(Of Data)
Dim element As Dati
sql = "SELECT * from demo.table"
command = New Odbc.OdbcCommand(sql, odbcConn)
Try
recordSet = command.ExecuteReader
While recordSet.Read()
element = New Data
element.id = recordSet(0) 'column name: recordSet.GetName(0)
element.name = recordSet(1) 'column name: recordSet.GetName(1)
element.description = recordSet(2) 'column name: recordSet.GetName(2)
element.address = recordSet(3) 'column name: recordSet.GetName(3)
dataLst.Add(element)
End While
ret.arrDati = dataLst

How do I set the value for an Invoice custom field using the QuickBooks V3 DataService?

I am attempting to create new invoices in QuickBooks using the V3 API. I have the invoice creation working perfectly, except I cannot set the values for the 3 custom fields.
I need a VB or C# resolution that utilizes the AnyIntuitObject property in this context.
Here is the code that I am attempting to implement:
Dim serviceContext As ServiceContext = getServiceContext(profile)
Dim invoiceDataService As New DataService(serviceContext)
Dim oInvoice As New Invoice()
oInvoice.DocNumber = "8675309"
oInvoice.TxnDate = DateTime.Today.Date
oInvoice.TxnDateSpecified = True
oInvoice.CustomerRef = New ReferenceType() With {.Value = "1885", .name = "QBT"}
Dim cField As New CustomField()
cField.DefinitionId = 1
cField.Name = "MyCustomFieldName"
cField.Type = CustomFieldTypeEnum.StringType
cField.AnyIntuitObject = New String() {"MyCustomFieldValue"}
oInvoice.CustomField = New CustomField() {cField}
Dim invLine As New Line()
invLine.Amount = 999.99D
invLine.AmountSpecified = True
invLine.DetailType = LineDetailTypeEnum.SalesItemLineDetail
invLine.DetailTypeSpecified = True
invLine.AnyIntuitObject = New SalesItemLineDetail With
{
.ItemElementName = ItemChoiceType.UnitPrice,
.AnyIntuitObject = 999.99D,
.Qty = 1D,
.ItemRef = New ReferenceType() With {.name = "Service", .Value = "529"}
}
oInvoice.Line = New Line() {invLine}
Dim invoiceAdded As Invoice = invoiceDataService.Add(Of Invoice)(oInvoice)
I have reviewed every thread I can find pertaining to custom fields and the API and still have not found a resolution.
Any help that can be provided would be greatly appreciated!
Resolved the issue by using the following:
Dim customFieldList As New List(Of CustomField)
Dim cField As New CustomField()
cField.DefinitionId = 2
cField.Name = "Week ending"
cField.Type = CustomFieldTypeEnum.StringType
cField.AnyIntuitObject = inv.WeekEnding.ToString("MM/dd/yyyy")
customFieldList.Add(cField)
oInvoice.CustomField = customFieldList.ToArray

how to add new row after filling all textboxes, not replace old row in gridview?

i wrote program in vb.net. in my page, i have 3 textbox. in Txt_CardBarcode_TextChanged ,i wrote this codes:
Try
Dim stream_CardBarcode As System.IO.MemoryStream = New System.IO.MemoryStream
Dim cls As New Cls_Barcode
Dim pic_CardBarcode As System.Drawing.Image = Nothing
cls.btnEncode(pic_CardBarcode, Txt_CardBarcode.Text.Trim)
pic_CardBarcode.Save(stream_CardBarcode, System.Drawing.Imaging.ImageFormat.Png)
Dim f_cardBarcode As IO.FileStream = _
New IO.FileStream("C:\fafa.png", IO.FileMode.Create, IO.FileAccess.ReadWrite)
Dim b_cardBarcode As Byte() = stream_CardBarcode.ToArray
f_cardBarcode.Write(b_cardBarcode, 0, b_cardBarcode.Length)
f_cardBarcode.Close()
Dim ds As DS_Test
ds = New DS_Test
Dim Val_LabelBarcode() = {stream_CardBarcode.ToArray, Txt_ICCID.Text.Trim}
ds.Tables(2).Rows.Add(Val_LabelBarcode)
crp_CardBarcode.SetDataSource(ds.Tables(2))
Dim frm_CrpCardBarcode As New Frm_RepCardBarcode
frm_CrpCardBarcode.CrystalReportViewer1.ReportSource = crp_CardBarcode
GVSimInfo.DataSource = ds.Tables(2)
ds.Tables(2).Rows.Add(1)
GVSimInfo.Rows(GVSimInfo.Rows.Count - 1).Cells(0).Value = True
ds.Tables(2).Rows(0).Item(0) = True
ds.Tables(2).Rows(0).Item(1) = ""
ds.Tables(2).Rows(0).Item(2) = Txt_ICCID.Text
ds.Tables(2).Rows(0).Item(3) = ""
ds.Tables(2).Rows(0).Item(4) = ""
now, in run time, after filling 3textbox, new row add to gridview , but when user want to more than filling textboxes, new row in grid view replace on old row!!!
how to set new row add to grid view , instead of replace old row?
in my dataset, i put 3tables. tables(2) has 2 columns that save image barcode with byte array data type, but in my gridview ,i have 5 columns.
in run time give me error dialog,it is images from it:
If your DGV is not bound to any data Source:
GVSimInfo.Rows.Add(1);
If your DGV is bound to some Data Source then :
ds.Tables(2).Rows.Add(1)
Add this code after your last text box is filled and new row is needed.
to set the values you can use :
ds.Tables(2).Rows(0).Item("Column_number") = "your text"
Try
Dim stream_CardBarcode As System.IO.MemoryStream = New System.IO.MemoryStream
Dim cls As New Cls_Barcode
Dim pic_CardBarcode As System.Drawing.Image = Nothing
cls.btnEncode(pic_CardBarcode, Txt_CardBarcode.Text.Trim)
pic_CardBarcode.Save(stream_CardBarcode, System.Drawing.Imaging.ImageFormat.Png)
Dim f_cardBarcode As IO.FileStream = _
New IO.FileStream("C:\fafa.png", IO.FileMode.Create, IO.FileAccess.ReadWrite)
Dim b_cardBarcode As Byte() = stream_CardBarcode.ToArray
f_cardBarcode.Write(b_cardBarcode, 0, b_cardBarcode.Length)
f_cardBarcode.Close()
Dim ds As DS_Test
ds = New DS_Test
Dim Val_LabelBarcode() = {stream_CardBarcode.ToArray, Txt_ICCID.Text.Trim}
ds.Tables(2).Rows.Add(Val_LabelBarcode)
crp_CardBarcode.SetDataSource(ds.Tables(2))
Dim frm_CrpCardBarcode As New Frm_RepCardBarcode
frm_CrpCardBarcode.CrystalReportViewer1.ReportSource = crp_CardBarcode
ds.Tables(2).Rows.Add(1)
GVSimInfo.Rows(GVSimInfo.Rows.Count - 1).Cells(0).Value = True
ds.Tables(2).Rows(0).Item(0) = True
ds.Tables(2).Rows(0).Item(1) = ""
ds.Tables(2).Rows(0).Item(2) = Txt_ICCID.Text
ds.Tables(2).Rows(0).Item(3) = ""
ds.Tables(2).Rows(0).Item(4) = ""
GVSimInfo.DataSource = ds.Tables(2) <-------

Unable To Change SeriesChartType Dynamically in MS Chart Control

I am using the MS Chart control (version 3.5.0).
I have added it by using the designer (drag and drop). I removed the default "Series1" from the Properties -> Series -> Collection so that the chart contains no data.
I am adding the data at runtime based on a canned query to a SQLite DB. Like so:
Dim SQL As String = "SELECT * FROM ageLength ORDER BY month"
Dim cmd As New SQLiteCommand(SQL)
Dim SqLiteConnection1 As SQLiteConnection = New SQLiteConnection()
SqLiteConnection1.ConnectionString = "Data Source=" & My.Application.Info.DirectoryPath & "\Data\UserData.db3;"
cmd.Connection = SqLiteConnection1
Dim da As New SQLiteDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds, "ageLength")
Dim Series1 As Series = New Series()
Dim Series2 As Series = New Series()
Series1.Name = "Pcnt2nd"
Series1.ChartType = SeriesChartType.Spline
Series2.Name = "Pcnt98th"
Series2.ChartType = SeriesChartType.Spline
Chart1.Series.Add("Pcnt2nd")
Chart1.Series.Add("Pcnt98th")
Chart1.Series("Pcnt2nd").XValueMember = "month"
Chart1.Series("Pcnt2nd").YValueMembers = "Pcnt2nd"
Chart1.Series("Pcnt98th").XValueMember = "month"
Chart1.Series("Pcnt98th").YValueMembers = "Pcnt98th"
Chart1.DataSource = ds.Tables(0)
The data is displayed on the Chart, however, it is a Bar type graph. I set it to use the Spline type for both series. I am not sure what I missed. Any input is greatly appreciated.
After doing a lot more messing around I found the solution:
I remove these 2 lines:
Series1.ChartType = SeriesChartType.Spline
Series2.ChartType = SeriesChartType.Spline
And then I add these 2 lines:
Chart1.Series("Pcnt2nd").ChartType = DataVisualization.Charting.SeriesChartType.Line
Chart1.Series("Pcnt98th").ChartType = DataVisualization.Charting.SeriesChartType.Line
Not sure why that is...but there you have it.