Connection problem

pachjo

Well-known member
Joined
Dec 12, 2006
Messages
370
Programming Experience
10+
I am getting a tad confused as to why I get an error for the code below whereby the second block errors stating invalid object 'transactions'

VB.NET:
[SIZE=2]taImportData = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlClient.SqlDataAdapter(strSQLString, glb_cnMM2007)
taImportData.Fill(dtImportData)
 
strSQLString = [/SIZE][SIZE=2][COLOR=#a31515]"SELECT MAX(tran_date) FROM transactions"
[/COLOR][/SIZE][SIZE=2]taTransactions = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlClient.SqlDataAdapter(strSQLString, glb_cnMM2007)[/SIZE]
[SIZE=2][SIZE=2]taTransactions.Fill(dtTransactions)
[/SIZE]
[/SIZE]

but if I do this it works?

VB.NET:
[SIZE=2][SIZE=2]strSQLString = [/SIZE][SIZE=2][COLOR=#a31515]"SELECT MAX(tran_date) FROM transactions"
[/COLOR][/SIZE][SIZE=2]taTransactions = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlClient.SqlDataAdapter(strSQLString, glb_cnMM2007.ConnectionString)
taTransactions.Fill(dtTransactions)
[/SIZE][/SIZE]

glb_cnnMM2007 is a global connection variable that is set to my.settings.connectionstring from the main application form on opening.

How come the first block and all other blocks throughout the app accepts it on its own yet the transactions one differs?

The table transactions exists in the database!
 
To date all works OK.
Recommend leaving it alone, and consider that in New mode, all this code would have been a case of:

Write an SQL
Drag/drop an icon on a form
Add one line of code to a button..


All the code you wrote is, more or less, in it somewhere, but most of it is written by the IDE, you see..
 
parameterised data

sqladapter.SelectCommand = New OdbcCommand("SELECT * from " & table & "where date between @from_date and @to_date", conn)



sqladapter.SelectCommand.Parameters.Add("@from_date", OdbcType.date, "date").Value = Me.DateTimePicker1.Value.ToShortDateString


sqladapter.SelectCommand.Parameters.Add("@to_date", OdbcType.date, "date").Value = Me.DateTimePicker2.Value.ToShortDateString


i tried these codes but when was prompt error " date type cannot convert to int"

how do i solve the prob?
 
Back
Top