Hey guys,
I'm fairly new to VB.NET, but not development, and believe it or not, I've spent the past two days trying to get nothing more than a simple INSERT to work. I've already posted on a couple other forums, but never got the problem solved. Below is my entire Sub Main(), and any advice to what I'm doing wrong would be really, really appreciated right now.
I manually inserted one record into the 'accounts' table, and it always shows up just fine, and stays in the table. When I run the following code, the extra two records are successfully inserted into the database and show up in the combo box as needed, but when I exit the application, those two records always disappear. Why aren't the records being saved / updated / commited?
Any help you could offer would be great. BTW... I know the code is messy, but I'm just trying to make it work for now, and will worry about cleaning it up later. Thanks guys.
Thanks,
Matt
I'm fairly new to VB.NET, but not development, and believe it or not, I've spent the past two days trying to get nothing more than a simple INSERT to work. I've already posted on a couple other forums, but never got the problem solved. Below is my entire Sub Main(), and any advice to what I'm doing wrong would be really, really appreciated right now.
I manually inserted one record into the 'accounts' table, and it always shows up just fine, and stays in the table. When I run the following code, the extra two records are successfully inserted into the database and show up in the combo box as needed, but when I exit the application, those two records always disappear. Why aren't the records being saved / updated / commited?
Any help you could offer would be great. BTW... I know the code is messy, but I'm just trying to make it work for now, and will worry about cleaning it up later. Thanks guys.
VB.NET:
Sub Main()
Dim accountAdapter As New AccountInfoDataSetTableAdapters.accountsTableAdapter
accountAdapter.Insert("testing", 23, "developer", 1)
Dim accountDataSet As DataSet = New AccountInfoDataSet
Dim newRow As DataRow = accountDataSet.Tables("accounts").NewRow()
newRow("username") = "blah"
newRow("account_id") = 235
newRow("type") = "developer"
newRow("default_account") = 1
accountDataSet.Tables("accounts").Rows.Add(newRow)
accountDataSet.AcceptChanges()
'Try to update (doesn't work)
'accountAdapter.Update(accountDataSet)
Dim newRows As DataTable = accountDataSet.Tables("accounts").GetChanges(Data.DataRowState.Added)
accountAdapter.Update(newRows)
'Connect to the database
AccountDBConnection.Open()
'Get needed info
Dim SQLcmd As New SqlCommand("SELECT username,default_account FROM accounts", AccountDBConnection)
Dim myReader As SqlDataReader = SQLcmd.ExecuteReader()
'Check for existing accounts
If (myReader.HasRows) Then
Dim x As Integer = 0
frmLogin.Show()
While (myReader.Read())
frmLogin.comboUsername.Items.Add(myReader.GetString(0))
If myReader.GetInt32(1) = 1 Then
frmLogin.comboUsername.SelectedIndex = x
End If
x = x + 1
End While
Else
frmCreateAccount.Show()
End If
myReader.Close()
Application.Run()
AccountDBConnection.Close()
MsgBox("DONE")
End Sub
Thanks,
Matt