I have the following vb.net code that populates a datagrid (I didn't include that part of the code), I would also like to save it in a string variable that will later be used to export to Excel:
Dim con As New SqlConnection
Dim cmd As New SqlCommand
con.ConnectionString = "Data Source=myServer;Initial Catalog=myDB;Integrated Security=True"
cmd.Connection = con
cmd.CommandText = "SELECT Division, CustomerNo, SalesOrderNumber,InvoiceNumber, InvoiceDate, CustomerPO,ShipToName, ShipToCity, ShipToState, ShipToZipCode,tblFreightFactor.Carrier, ShipmentType FROM tblFreightFactor INNER JOIN tblFreightFactor_Carriers ON tblFreightFactor.Carrier = tblFreightFactor_Carriers.Carrier WHERE ( CarrierName = @FreightFactorCriteria) And (InvoiceDate >= @InvoiceStartDate) And (InvoiceDate <= @InvoiceEndDate) ORDER BY InvoiceDate"
Dim sda As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
I've tried the following:
Dim sql As String
sql = cmd.CommandText.ToString
But that includes the @parameters instead of the actual parameter. So I don't want the results but the entire SELECT statement from the commandtext with the actual parameters. How can I get this to work?
Thank you in advance.