SQL Statement help in vb.net - sql

Sub Bind_dgList()
Dim strCommand As String
Dim strConnect As String
Dim DBDataAdapter_Leads As OleDbDataAdapter
Dim DBConnection_List As OleDbConnection
Dim DBDataSet_Leads As DataSet
Dim DBDataView_Leads As DataView
strConnect = GetDBConnectionString()
DBConnection_List = New OleDbConnection(strConnect)
strCommand = "SELECT * Manager FROM tblList ORDER BY Names"
DBDataAdapter_Leads = New OleDbDataAdapter(strCommand, DBConnection_List) DBDataSet_Leads = New DataSet
DBDataAdapter_Leads.Fill(DBDataSet_Leads, "tblList")
DBDataView_Leads = New DataView(DBDataSet_Leads.Tables("tblList"))
dgList.DataSource = DBDataView_Leads
dgList.DataBind()
End Sub
Can anyone help me with the above code? I want to select distinct record of names. Some of the names are repeating. May I know how to do it?
I have used all the above. But There is an error showing.
First error : Server Error in '/wwwroot' Application. Syntax error (missing operator) in query expression '* Manager'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Syntax error (missing operator) in query expression '* Manager'.
Source Error: Line 71: DBDataAdapter_FocalLeads = New OleDbDataAdapter(strCommand, DBConnection_AgentList) Line 72: DBDataSet_FocalLeads = New DataSet Line 73: DBDataAdapter_FocalLeads.Fill(DBDataSet_FocalLeads, "tblAgentList") Line 74: DBDataView_FocalLeads = New DataView(DBDataSet_FocalLeads.Tables("tblAgentList"))
Line 75:
Second Error : DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'FieldId'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'FieldId'.
Source Error: Line 75: Line 76: dgAgentList.DataSource = DBDataView_FocalLeads Line 77: dgAgentList.DataBind() Line 78: End Sub
Line 79:
But When am using this there is no error, but the manager names are repeating. strCommand = "SELECT * FROM tblAgentList ORDER BY Manager"
Am doing this to mass edit and update the records. If I can get help in doing the mass updating I can ignore this page. Now I have to edit line by line. So if there is change in a managers role and its repeating 5 times. I need to manually edit one by to update. So is there a way to do a mass update?
Thank you for the help.. I really appreciate.. :)
I have used all the above. But There is an error showing.
First error : Server Error in '/wwwroot' Application.
Syntax error (missing operator) in query expression '* Manager'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Syntax error (missing operator) in query expression '* Manager'.
Source Error:
Line 71: DBDataAdapter_FocalLeads = New OleDbDataAdapter(strCommand, DBConnection_AgentList)
Line 72: DBDataSet_FocalLeads = New DataSet
Line 73: DBDataAdapter_FocalLeads.Fill(DBDataSet_FocalLeads, "tblAgentList")
Line 74: DBDataView_FocalLeads = New DataView(DBDataSet_FocalLeads.Tables("tblAgentList"))
Line 75:
Second Error : DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'FieldId'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'FieldId'.
Source Error:
Line 75:
Line 76: dgAgentList.DataSource = DBDataView_FocalLeads
Line 77: dgAgentList.DataBind()
Line 78: End Sub
Line 79:
But When am using this there is no error, but the manager names are repeating.
strCommand = "SELECT * FROM tblAgentList ORDER BY Manager"
Am doing this to mass edit and update the records. If I can get help in doing the mass updating I can ignore this page.
Now I have to edit line by line. So if there is change in a managers role and its repeating 5 times. I need to manually edit one by to update. So is there a way to do a mass update?
Thank you for the help.. I really appreciate.. :)

Did you mean:
SELECT * FROM Manager tblList ORDER BY Names
or
SELECT *, Manager FROM tblList ORDER BY Names
?

Modify your SQL statement like this
SELECT DISTINCT Names FROM Manager
ORDER BY Names
I don't think
SELECT * FROM
will work.

Assuming the rest of the code works all you should need to do is change this line
strCommand = "SELECT * Manager FROM tblList ORDER BY Names"
to this
strCommand = "SELECT DISTINCT * Manager FROM tblList ORDER BY Names"

Related

Groups' permission from gsuite API Json error "Error cannot be deserialized" Vb .Net

I'm trying to retrieve permissions for my groups.
I followed the article: (GET) and converted it to vb.net
Dim GrpListReq As New Google.Apis.Groupssettings.v1.GroupsResource.GetRequest(service, strEmail)
Dim first = GrpListReq.Execute.Email
However, I'm getting the following error:
"An Error occurred, but the error response could not be deserialized."
Inner exception gives:
"Error parsing NaN value. Path '', line 0, position 0."
Any help will be greatly appreciated.

[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '='

I have started getting an error on a page and am really struggling to work out the cause of this. I have searched on Stack Overflow for this same error message and found some people that got it also, but there solutions were very different to mine. This is the error message I'm getting:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '='.
/test-page.asp, line 97
This related to this line on that .asp page:
set rsMainContact=oConn.execute
("SELECT * FROM tbl_individual WHERE individual_id="&iMainContact)
Now the strange thing about this is that the page is actually bringing up the correct data, it's getting all the data it needs from that table. Which is why I don't understand why there's a problem.
Also, when I run the query using the "SELECT * FROM tbl_individual WHERE individual_id="&iMainContact" statement in MSSQL, replacing &iMainContact for an actual variable, it works absolutely fine.
Does anyone have any idea why this error might be occurring?
In case you want to know where the various variables come from then this is also some relevant code from the page:
SET rsOrganisationPendingOrganic=Server.CreateObject("ADODB.RecordSet")
rsOrganisationPendingOrganic.CursorType=3
rsOrganisationPendingOrganic.Open sSQL, oConn
iOrganisationPendingOrganicCount=rsOrganisationPendingOrganic.RecordCount
iMainContact=rsOrganisationPendingOrganic("organisation_maincontact")
if the following code is run BEFORE the error occurs, you most likely have no value for iMainContact:
SET rsOrganisationPendingOrganic=Server.CreateObject("ADODB.RecordSet")
rsOrganisationPendingOrganic.CursorType=3
rsOrganisationPendingOrganic.Open sSQL, oConn
iOrganisationPendingOrganicCount=rsOrganisationPendingOrganic.RecordCount
iMainContact=rsOrganisationPendingOrganic("organisation_maincontact")
you can prove this by writing out the sql to the screen before executing the failing sql:
Response.Write "SELECT * FROM tbl_individual WHERE individual_id=" & iMainContact
Response.End
I also agree 1000% with lad2025, use parameterized queries to guard against sql injection

Why is "using" seemingly rejected in one function, but okay in another?

With this code:
Protected Function GetArgValsForCompanyName(coName As String) As String()
Dim args(2) As String
Using con As New SqlConnection("SERVER=PLATYPUS42;DATABASE=duckbilldata;UID=durante;PWD=pondscum"),
cmd As New SqlCommand("select Unit, MemberNo, CustNo from Customers WHERE CompanyName = #CoName", con)
con.Open()
cmd.CommandType = CommandType.Text
cmd.Parameters.Add("#CoName", SqlDbType.VarChar, 50).Value = coName
Using reader As SqlDataReader = cmd.ExecuteReader
While reader.Read
args(0) = reader.Item(0).ToString()
args(1) = reader.Item(1).ToString()
args(2) = reader.Item(2).ToString()
End While
End Using
End Using
Return args
End Function
...I get:
Server Error in '/EMS/customerreportingnet' Application.
--------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30203: Identifier expected.
Source Error:
Line 94: Dim args(2) As String
Line 95:
Line 96: Using con As New SqlConnection("SERVER=PLATYPUS42;DATABASE=duckbilldata;UID=durante;PWD=pondscum"),
Line 97: cmd As New SqlCommand("select Unit, MemberNo, CustNo from Customers WHERE CompanyName = #CoName", con)
Line 98:
Source File: C:\EnhancedMonthlySalesReporting\customerreportingnet\customerreportingnet\pages\custmaint_categoryadmin.aspx.vb Line: 96
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.5485; ASP.NET Version:2.0.50727.5491
So, the "using con" line is implicated as the problem. I commented out most of the code to just return some random values, and it works fine.
However, there is another "Using" being used: the Button1_Click event handler uses a using. Does it not complain only because the button has not been clicked?
Actually, when I click the button, I do get an error, but it's not about the using; it's because I apparently have too many controls on the form that the button deals with (thousands or label/checkbox pairs, in fact):
Server Error in '/EMS/customerreportingnet' Application.
--------------------------------------------------------------------------------
Operation is not valid due to the current state of the object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Operation is not valid due to the current state of the object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: Operation is not valid due to the current state of the object.]
System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() +4198079
System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) +60
System.Web.HttpRequest.FillInFormCollection() +189
[HttpException (0x80004005): The URL-encoded form data is not valid.]
System.Web.HttpRequest.FillInFormCollection() +11196408
System.Web.HttpRequest.get_Form() +119
System.Web.TraceContext.InitRequest() +1188
System.Web.TraceContext.VerifyStart() +133
System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +11307449
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +452
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.5485; ASP.NET Version:2.0.50727.5491
So is it really the "using" that's the problem in the first block of code? Is there a way to still use it, or do I need to revert to the olde-[fangl,fashion]ed way of creating objects?
In VB.NET, the line continuation character allows to treat two lines as one from the point of view of the compiler. This character is the underscore and should be the last one on the line.
This requirement has been largely removed by latest version of VB.NET Compiler that has enough intelligence to understand where the statements end.
For example in LinqPAD 5.10 there is no need to use this character between the two using statement.
Instead, It seems that your current compiler cannot understand this and adding the continuation character should solve the problem
Using con As New SqlConnection("SERVER=PLATYPUS42;DATABASE=duckbilldata;UID=durante;PWD=pondscum"), _
cmd As New SqlCommand("select Unit, MemberNo, CustNo from Customers WHERE CompanyName = #CoName", con)

Occasional Script Task error in SSIS

I am going through a very peculiar situation while executing a package. The derived columns in all the DFTs in the package have been replaced with Script tasks due to a business requirement.
Executing the package on development resulted in an occasional error sometimes with the error statement as 'Value is too large to be added to the buffer' and sometimes the script task failed stating
System.ArgumentOutOfRangeException: Year, Month, and Day parameters
describe an un-representable DateTime
OR
The milliseconds value is out of bounds (not between 0 & 999).
Some other error messages received during the executions are stated below:-
Description: Unspecified error End Error Error: 2016-11-24
10:51:03.37 Code: 0xC0047062 Source: Dft_x [279]
Description: System.ArgumentOutOfRangeException: Year, Month, and Day
parameters describe an un-representable DateTime. at
Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.HandleUserException(Exception
e) at
Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(Int32
inputID, PipelineBuffer buffer) at
Microsoft.SqlServer.Dts.Pipeline.ManagedComponentHost.HostProcessInput(IDTSManagedComponentWrapper100
wrapper, Int32 inputID, IDTSBuffer100 pDTSBuffer, IntPtr
bufferWirePacket) End Error Error:
&
[SSIS.Pipeline] Error: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The
PrimeOutput method on Flat File Source 1 returned error code
0xC02020C4. The component returned a failure code when the pipeline
engine called PrimeOutput(). The meaning of the failure code is
defined by the component, but the error is fatal and the pipeline
stopped executing. There may be error messages posted before this
with more information about the failure.
[OleDst_Pricing [165]] Error: SSIS Error Code DTS_E_OLEDBERROR. An
OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is
available. Source: "Microsoft SQL Server Native Client 11.0"
Hresult: 0x80004005 Description: "Invalid date format".
[OleDst_xyz [165]] Error: There was an error with
OleDst_xyz.Inputs[OLE DB Destination Input].Columns[DateColumn] on
OleDst_xyz.Inputs[OLE DB Destination Input]. The column status
returned was: "Conversion failed because the data value overflowed the
specified type.". [OleDst_x [165]] Error: SSIS Error Code
DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "OleDst_xyz.Inputs[OLE
DB Destination Input]" failed because error code 0xC020907A occurred,
and the error row disposition on "OleDst_xyz.Inputs[OLE DB
Destination Input]" specifies failure on error. An error occurred on
the specified object of the specified component. There may be error
messages posted before this with more information about the failure.
[FltSrc_x 1 [313]] Error: The attempt to add a row to the
Data Flow task buffer failed with error code 0xC0047020.
[SSIS.Pipeline] Error: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The
PrimeOutput method on FltSrc_BR_x 1 returned error code
0xC02020C4. The component returned a failure code when the pipeline
engine called PrimeOutput(). The meaning of the failure code is
defined by the component, but the error is fatal and the pipeline
stopped executing. There may be error messages posted before this
with more information about the failure.
However after tweaking the DefaultMaxBufferRows & DefaultMaxBufferSize property, I successfully executed the package individually and through SQL Server about 40 times on Development and Test environment to make sure it doesn't fail again. But the Production execution again failed with similar date specific error.
I am posting the code below contained in the Script Tasks which is similar in each of the DFTs:-
Public Class ScriptMain
Inherits UserComponent
Dim xyzArray() As String
Dim rowValue As String
Dim strDate As String
Dim columnxyz As String '= Me.Variables.MaterialMaster.ToString()
'Dim v1 As IDTSVariables100
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
rowValue = Row.XYZtoABC.ToString() + "~".ToString()
xyzArray = rowValue.Split(New Char() {"~"c})
strDate = Row.DateColumn.ToString()
columnxyz = Row.columnxyz.ToString()
CreateNewOutputRows()
End Sub
Public Sub CreateNewOutputRows()
ResultBuffer.AddRow()
ResultBuffer.xyz1 = xyzArray(1)
ResultBuffer.xyz2 = xyzArray(2)
ResultBuffer.xyz3 = xyzArray(3)
ResultBuffer.xyz4 = xyzArray(4)
ResultBuffer.xyz5 = xyzArray(5)
ResultBuffer.Datecolumn = CDate(strDate)
ResultBuffer.columnxyz = columnxyz
End Sub
End Class
The problem is data related. You are occasionally importing data that cannot be represented as a date, and trying to output it as a date. Since you don't have any code in place to catch this, you are getting an error.
You could put this line in a TRY .. CATCH block, and decide what to do in the cases where the string cannot be converted to a date:
ResultBuffer.Datecolumn = CDate(strDate)
If strDate has a specific format (i.e.: "dd-MM-yyyy HH:mm:ss"). you have to use Date.ParseExact() function like the following:
ResultBuffer.Datecolumn = Date.ParseExact(strDate,"dd-MM-yyyy HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None)
Also if you have many specific formats, you can declare a string array and pass it to this function like the following:
dim strFormats() as string = {"dd-MM-yyyy","yyyy-MM-dd"}
ResultBuffer.Datecolumn = Date.ParseExact(strDate,strFormats,System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None)
CDate function is related to your regional settings so it is best practice to work with Date.ParseExact
Another point is to use DB_TIMESTAMP as column type instead of DT_DATE

"SELECT ##IDENTITY" throws overflow error

I am working on an MS Access solution where I need to insert a row and use its ID from within VBA. Thankfully, SQL gave us ##IDENTITY for exactly this purpose.
Or so I thought. In practice, it throws an overflow error. What can be possible causes of such an error?
Multiple Google searches could not come up with a solution.
Full line of code:
iid = CurrentDb.OpenRecordset("SELECT ##IDENTITY")(0)
German error message:
Laufzeitfehler '6': Überlauf
Translation:
Runtime Error '6': Overflow
Perhaps you need to declare iid as a 'variant' instead of an 'integer'?
http://www.dbforums.com/microsoft-access/1666779-any-idea-why-i-get-runtime-error-6-overflow.html