Click here to Skip to main content
15,913,854 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: vb.net 2008 Express to SQL - Dataset does not show changes in DB Pin
Dave Kreskowiak11-Feb-10 5:02
mveDave Kreskowiak11-Feb-10 5:02 
GeneralRe: vb.net 2008 Express to SQL - Dataset does not show changes in DB Pin
William Winner11-Feb-10 6:34
William Winner11-Feb-10 6:34 
AnswerRe: vb.net 2008 Express to SQL - Dataset does not show changes in DB Pin
William Winner11-Feb-10 6:16
William Winner11-Feb-10 6:16 
AnswerRe: vb.net 2008 Express to SQL - Dataset does not show changes in DB Pin
William Winner11-Feb-10 6:21
William Winner11-Feb-10 6:21 
GeneralRe: vb.net 2008 Express to SQL - Dataset does not show changes in DB Pin
gengel11-Feb-10 18:28
gengel11-Feb-10 18:28 
GeneralRe: vb.net 2008 Express to SQL - Dataset does not show changes in DB Pin
gengel11-Feb-10 18:30
gengel11-Feb-10 18:30 
GeneralRe: vb.net 2008 Express to SQL - Dataset does not show changes in DB Pin
gengel11-Feb-10 23:35
gengel11-Feb-10 23:35 
GeneralRe: vb.net 2008 Express to SQL - Dataset does not show changes in DB Pin
William Winner12-Feb-10 6:09
William Winner12-Feb-10 6:09 
You are correct...ADO.Net works with data offline. That's what I was saying. When you run an ExecuteNonQuery like in your second example, the DataSet that you filled previously will not reflect those changes because the DataSet is an offline version and the ExecuteNonQuery is updating the Online Version.

The FillSchema should do the trick...though I'm not as familiar with it...it looks like it's there to set up the TableMapping for you. That will work for the first example. Let me show you an example of code that I run to add a new row to a database called "1 Populations"

VB
Dim openedConnectionString As Boolean = False
If Not connectionString.State = ConnectionState.Open Then
    connectionString.Open()
    openedConnectionString = True
End If

Dim insertionDS As New DataSet
Dim newDataAdapter As OleDbDataAdapter

Dim sql As String = "SELECT * FROM [" & ActiveProject.Identifier & " Populations] ORDER BY ID;"
newDataAdapter = New OleDb.OleDbDataAdapter(sql, connectionString)

'Create mapping
newDataAdapter.TableMappings.Add("Table", "Populations")
With newDataAdapter.TableMappings(0).ColumnMappings
    .Add("ID", "ID")
    .Add("Name", "Name")
    .Add("Char ID", "Char ID")
    .Add("Stratum", "Stratum")
    .Add("PopLevel", "PopLevel")
End With

'Make sure field names are bracketed
Dim cb As New OleDbCommandBuilder(newDataAdapter)
cb.QuotePrefix = " ["
cb.QuoteSuffix = "] "

'Add Table
newDataAdapter.Fill(insertionDS)

'Get last ID number to increment
Dim lastIndex As Integer = 0

With insertionDS.Tables("Populations")
    If .Rows.Count <> 0 Then
        lastIndex = .Rows(.Rows.Count - 1).Item("ID")
    End If

    'Insert record
    Dim newRow As DataRow = .Rows.Add

    newRow.BeginEdit()
    newRow.Item("ID") = lastIndex + 1
    newRow.Item("Name") = Population
    newRow.Item("Char ID") = ""
    newRow.Item("Stratum") = Stratum
    newRow.Item("PopLevel") = Level
    newRow.EndEdit()
End With

'Save changes
newDataAdapter.InsertCommand = cb.GetInsertCommand
newDataAdapter.Update(insertionDS)

newDataAdapter.Dispose()

'If we opened the connectionstring, then close it
If openedConnectionString Then
    connectionString.Close()
End If


When I run this, it adds a new row to both the DataSet and the Database.
QuestionInternet Connection with VB 6 Pin
jayachandra.c10-Feb-10 19:45
jayachandra.c10-Feb-10 19:45 
AnswerRe: Internet Connection with VB 6 Pin
Eddy Vluggen10-Feb-10 21:27
professionalEddy Vluggen10-Feb-10 21:27 
GeneralRe: Internet Connection with VB 6 Pin
rhuiden11-Feb-10 8:56
rhuiden11-Feb-10 8:56 
QuestionHow to conver Exhadecimal to Text ? Pin
Golden Jing10-Feb-10 17:14
Golden Jing10-Feb-10 17:14 
AnswerRe: How to conver Exhadecimal to Text ? Pin
Eddy Vluggen10-Feb-10 21:46
professionalEddy Vluggen10-Feb-10 21:46 
GeneralRe: How to conver Exhadecimal to Text ? Pin
Golden Jing11-Feb-10 1:05
Golden Jing11-Feb-10 1:05 
GeneralRe: How to conver Exhadecimal to Text ? Pin
Golden Jing11-Feb-10 15:42
Golden Jing11-Feb-10 15:42 
GeneralRe: How to conver Exhadecimal to Text ? Pin
Eddy Vluggen12-Feb-10 0:02
professionalEddy Vluggen12-Feb-10 0:02 
GeneralRe: How to conver Exhadecimal to Text ? Pin
Golden Jing14-Feb-10 22:15
Golden Jing14-Feb-10 22:15 
QuestionFile Transfer from PPC Pin
Dominick Marciano10-Feb-10 9:28
professionalDominick Marciano10-Feb-10 9:28 
Questionclient in same lan help me Pin
Cosby10-Feb-10 5:26
Cosby10-Feb-10 5:26 
AnswerRe: client in same lan help me Pin
Eddy Vluggen10-Feb-10 21:49
professionalEddy Vluggen10-Feb-10 21:49 
GeneralRe: client in same lan help me Pin
Cosby10-Feb-10 21:54
Cosby10-Feb-10 21:54 
QuestionWake On Lan HELP Pin
Cosby10-Feb-10 5:25
Cosby10-Feb-10 5:25 
QuestionObject null reference exception Pin
ademsandeepreddy10-Feb-10 2:48
ademsandeepreddy10-Feb-10 2:48 
AnswerRe: Object null reference exception Pin
dan!sh 10-Feb-10 2:51
professional dan!sh 10-Feb-10 2:51 
GeneralObject null reference exception Pin
ademsandeepreddy10-Feb-10 3:08
ademsandeepreddy10-Feb-10 3:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.