Did not find a simple answer as to how to insert multiple rows of raw data into an Access database using an Insert Into SQL statement, this post is one of many to point out that VALUES is for single-row inserts, and you need to use a SELECT to insert more than 1 row - which means your values have to already be in the database.
I don't believe there's a straightforward way to do it with a single SQL statement, but you can use free MyOLEDBExpress database editing tool to accomplish it by cutting/pasting your columns of data from Excel spreadsheet or other source directly into a table. If you are combining data with values already in the database you can use a SELECT clause with the INSERT INTO statement to extract the insert values from tables.
It may be worth the effort if you have hundreds of rows of data or more. Here's the Insert statement after the temp table has been created.
INSERT INTO the_Access_Table (field1, field2) SELECT col1, col2 FROM temp_Table INNER JOIN other_Table ....
Wednesday, May 19, 2010
Thursday, March 25, 2010
VB.net Opening Connection to SQLServer
Was unable to connect from Visual Basic .NET 2008 to a SQL Server Express 2008 database using the online examples. I was getting the error "network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible"
Changing from Data Source=(local) to Data Source=.\SQLEXPRESS fixed the issue
Full example:
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim dr As SqlDataReader
myConnection = New SqlConnection("Data Source=.\SQLEXPRESS;User ID=youruser;Password=yourpassword;Initial Catalog=yourdatabase")
Try
myConnection.Open()
myCommand = New SqlCommand("Select * from tblRoom", myConnection)
dr = myCommand.ExecuteReader()
While dr.Read()
MessageBox.Show("Field1 " & dr(0).ToString() & " Field2 " & dr(1).ToString())
End While
dr.Close()
myConnection.Close()
Catch e As Exception
'handle errors
End Try
Changing from Data Source=(local) to Data Source=.\SQLEXPRESS fixed the issue
Full example:
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim dr As SqlDataReader
myConnection = New SqlConnection("Data Source=.\SQLEXPRESS;User ID=youruser;Password=yourpassword;Initial Catalog=yourdatabase")
Try
myConnection.Open()
myCommand = New SqlCommand("Select * from tblRoom", myConnection)
dr = myCommand.ExecuteReader()
While dr.Read()
MessageBox.Show("Field1 " & dr(0).ToString() & " Field2 " & dr(1).ToString())
End While
dr.Close()
myConnection.Close()
Catch e As Exception
'handle errors
End Try
Friday, December 4, 2009
JDI thread evaluations - Exception processing async thread queue
After some debugging Eclipse may throw an async thread exception every time it hits a breakpoint. The message is along the lines of
JDI thread evaluations
Exception processing async thread queue
You can clean this up by removing all watch statements and all breakpoints and restarting Eclipse.
JDI thread evaluations
Exception processing async thread queue
You can clean this up by removing all watch statements and all breakpoints and restarting Eclipse.
Wednesday, November 11, 2009
Firebird -902 error localhost refused connection
Seems too obvious but you will get this error if you try to Connect after you Stop or Pause your Firebird Server service. More common causes are amply documented on the web - Firewall blocking and Incorrect port # (default is 3050)
Thursday, September 17, 2009
Launching CHM help file from a Java application on Windows
Seems like an obvious need but could not find an example for how to launch a compiled HTML help file from inside a Java JAR application on a Windows machine, so here's one:
String myHelpfile = path + "help.chm";
String[] command = { "hh.exe", myHelpfile };
try {
Process proc = Runtime.getRuntime().exec(command);
} catch (IOException e) {
e.printStackTrace();
}
String myHelpfile = path + "help.chm";
String[] command = { "hh.exe", myHelpfile };
try {
Process proc = Runtime.getRuntime().exec(command);
} catch (IOException e) {
e.printStackTrace();
}
Friday, August 28, 2009
Removing requirement for NET Framework 3.5 from setup projects
A new setup and deployment project in Visual Basic 2008 will by default require .NET Framework 3.5 on the target machine
If your application targets .NET Framework 2.0 this is a waste of time
To change the requirement right-click on your setup project, select View, Launch Conditions, go to properties of the ".NET Framework" item under the Launch Conditions node and change the Version property to 2.0.50727
If your application targets .NET Framework 2.0 this is a waste of time
To change the requirement right-click on your setup project, select View, Launch Conditions, go to properties of the ".NET Framework" item under the Launch Conditions node and change the Version property to 2.0.50727
Friday, August 14, 2009
How to find the control that generated a postback
Had a little trouble finding a good example of how to identify the control that generated a postback within the page_load
There's a nice article for C#, after a bit of tinkering here's a VB implementation:
Public Function GetPostBackControl(ByVal curPage As Page) As Control
Dim foundControl As Control
Dim controlName As String = curPage.Request.Params.Get("__EVENTTARGET")
If (Not controlName Is Nothing And controlName <> "") Then
foundControl = curPage.FindControl(controlName)
Else
' control causing postback must be a Button or imageButton
For Each controlName In curPage.Request.Form.AllKeys
' image buttons have a ".x" or ".y" appended to name string
If (controlName.EndsWith(".x") Or controlName.EndsWith(".y")) then
controlName = controlName.Substring(0, controlName.Length - 2)
End If
Dim c As Control = curPage.FindControl(controlName)
If (TypeOf c Is Button Or TypeOf c Is ImageButton) Then
'first button we find is the one that caused the postback
foundControl = c
Exit For
End If
Next
End If
GetPostBackControl = foundControl
End Function
There's a nice article for C#, after a bit of tinkering here's a VB implementation:
Public Function GetPostBackControl(ByVal curPage As Page) As Control
Dim foundControl As Control
Dim controlName As String = curPage.Request.Params.Get("__EVENTTARGET")
If (Not controlName Is Nothing And controlName <> "") Then
foundControl = curPage.FindControl(controlName)
Else
' control causing postback must be a Button or imageButton
For Each controlName In curPage.Request.Form.AllKeys
' image buttons have a ".x" or ".y" appended to name string
If (controlName.EndsWith(".x") Or controlName.EndsWith(".y")) then
controlName = controlName.Substring(0, controlName.Length - 2)
End If
Dim c As Control = curPage.FindControl(controlName)
If (TypeOf c Is Button Or TypeOf c Is ImageButton) Then
'first button we find is the one that caused the postback
foundControl = c
Exit For
End If
Next
End If
GetPostBackControl = foundControl
End Function
Subscribe to:
Posts (Atom)