|
Hmm...ok, my first reply may not be your problem. I may have misunderstood your problem. Let me see if I understand now.
In the first example, I still believe it's because you haven't set up the TableMapping . Though, I have to say, your code is a little hard to read and I believe a little non-standard.
As to the second example, TableMapping isn't your issue because you're running ExecuteNonQuery . That section of code should update the database, but it won't update your DataTable in memory. You have to understand the basics of ADO.Net. When the DataTable is created, it basically makes a copy of the database in memory. It is not linked at all to the underlying Database. That's why you have to run the Update. If the TableMapping is set up properly, then, when the Update is called, it tells the DataAdapter to find the matching Table in the matching DataSet and update the cells based on their RowState property. If the RowState indicated Insert, then the SQL Insert is called. If the RowState says Modify, then it runs the SQL Update. If it says Delete, then it runs the SQL Delete.
But, there is no static link between your DataTable and the DataSet. When you run the SQL Insert, you also will have to refresh your DataTable, or insert the data into the DataTable as well.
|
|
|
|
|
If you're using ADO.Net, I believe you have to set up the TableMapping before the Update will work.
See: Table Mapping in ADO.Net[^]
|
|
|
|
|
As far as the second example...I don't think this is affecting it, because it doesn't look like you use it again, but you misspelled UNITS in the Select Statement.
Dim da As New SqlClient.SqlDataAdapter
da.SelectCommand = New SqlClient.SqlCommand("SELECT * FROM UNTIS", MAIN.data.Conn)
|
|
|
|
|
Hi,
I am a little confused now. the code that I am using is based on several references and websites. I thought that was the idea of ADO.net. Work with data offline. What is the corrct way of doing this.
I have tried to simplify my code below.
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class Example
Dim SQLcon As New SqlConnection
Dim pDS As New DataSet
Sub MakeConnect()
SQLcon.ConnectionString = "Data Source=192.168.10.24\BDMS;" & _
"Initial Catalog=FLATPAN;" & _
"User ID=flatpan;" & _
"Password=*********"
Try
SQLcon.Open()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Sub Load_Table()
Dim SQLstr As String = "SELECT * FROM Orders"
Try
'open connection
If SQLcon.State = ConnectionState.Closed Then
SQLcon.Open()
End If
Dim cmd As SqlCommand = New SqlCommand(SQLstr, SQLcon)
Dim da As New SqlDataAdapter(SQLstr, SQLcon)
da.Fill(pDS, "ORDERS")
'Added this to see if it helped
da.FillSchema(pDS, SchemaType.Mapped)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
'close connection
SQLcon.Close()
End Try
End Sub
Sub Add_New_Record()
Try
Dim dt As DataTable = pDS.Tables("Orders")
Dim dr As DataRow = dt.NewRow
dr.Item("OrderStatus") = "A"
dr.Item("SamsungRef") = "B"
dr.Item("ProductCode") = "C"
dr.Item("ProductSerialNo") = "D"
dr.Item("ProductionNo") = "E"
dt.Rows.Add(dr)
'Update new row to database
Dim qry As String = "SELECT * FROM Orders"
If SQLcon.State = ConnectionState.Closed Then SQLcon.Open()
Dim da1 As New SqlClient.SqlDataAdapter
da1.SelectCommand = New SqlClient.SqlCommand(qry, MAIN.data.Conn)
Dim cb1 As SqlClient.SqlCommandBuilder = New System.Data.SqlClient.SqlCommandBuilder(da1)
da1.Update(pDS, "Orders")
'Had to add this to register change in dataset
pDS.Tables.Remove("Orders")
'Reatach datatable to dataset. Refresh primary keys
MAIN.data.Load_Table("SELECT * FROM Orders", "Orders")
Catch ex As Exception
MessageBox.Show("Add_New_Record, " & ex.Message)
End Try
End Sub
End Class
|
|
|
|
|
Sorry this should just be
Load_Table
'Reatach datatable to dataset. Refresh primary keys
MAIN.data.Load_Table("SELECT * FROM Orders", "Orders")
|
|
|
|
|
I think I found the problem. Not sure why this makes a difference?
da.FillSchema(pDS, SchemaType.Source, TableName)
|
|
|
|
|
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"
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)
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
Dim cb As New OleDbCommandBuilder(newDataAdapter)
cb.QuotePrefix = " ["
cb.QuoteSuffix = "] "
newDataAdapter.Fill(insertionDS)
Dim lastIndex As Integer = 0
With insertionDS.Tables("Populations")
If .Rows.Count <> 0 Then
lastIndex = .Rows(.Rows.Count - 1).Item("ID")
End If
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
newDataAdapter.InsertCommand = cb.GetInsertCommand
newDataAdapter.Update(insertionDS)
newDataAdapter.Dispose()
If openedConnectionString Then
connectionString.Close()
End If
When I run this, it adds a new row to both the DataSet and the Database.
|
|
|
|
|
Hi All,
here just i want to know how to get the Internet connection Status in VB6 whether it is working/not working.
if yes, let me also know how it is?
Thanks in advance.
Jay
|
|
|
|
|
jayachandra.c wrote: here just i want to know how to get the Internet connection Status in VB6 whether it is working/not working.
The most used way would be using InternetGetConnectedState API. An example can be found here[^].
Alternatively, you could launch the Ping command and capture it's output. If you can Ping Google, you're online I are Troll
|
|
|
|
|
I would say that is not necessarily true. It depends on what you mean by 'working'. You could be connected but have DNS issues that would prevent a successful ping. I only say that because I did have DNS issues and ran into this often.
|
|
|
|
|
Dear All,
I have issue with the exhadecimal.
I want to convert it to text by VB.net and FoxPro 6.0.
But i do not know any thing about it.
Do you have any idea or solving of this problem ?
Thanks for your help...VB.Net
|
|
|
|
|
Golden Jing wrote: I have issue with the exhadecimal.
I want to convert it to text
The hexadecimal "&hFF" would have a tekstual representation that equals "FF".
Console.WriteLine(Convert.ToInt32("FF", 16)) The above example converts the value "FF" to a decimal value, which should be 255 for "FF".I are Troll
|
|
|
|
|
|
Dear Eddy,
Thanks for you help.
But now my problem now is that the hexadecimal is so long.
mean that it is sentent so i want to convert that to the text.
have any solving of that ?VB.Net
|
|
|
|
|
Golden Jing wrote: But now my problem now is that the hexadecimal is so long.
How long? 10 characters, 50 characters?
A hexadecimal number is alread 'shorter' then a decimal number (compare "255" to "FF"). One way to make the resulting string smaller would be by compressing[^] it.I are Troll
|
|
|
|
|
ohh it is not sure.
it is up to sentense.
so i cannot know how long it is.VB.Net
|
|
|
|
|
I'm trying to figure out how to transfer files from a PPC to a PC, however I'm trying to do this from a PPC application, not from a desktop app. I looked into using the OpenNETCF framework, but the file transfer methods through RAPI only work for desktop apps, and I can't find anything else that would seem to work in the OpenNETCF framework or the .NET CF. Basically in the PPC app the user would select a group of files that would be transfered to a predetermined folder on the PC. If the folder does not exist on the PC then it would be created and the files transfered. Anyone have any idea how this could be accomplished? Thanks in advanced.
|
|
|
|
|
Hi guys, how can i know if two PC are in the same lan??
Please help me
|
|
|
|
|
Cosby wrote: Hi guys, how can i know if two PC are in the same lan??
Do you really want to verify whether they're in the same network, or do you want to know whether the other PC is accessible over the network?
If the last is the case, then use the Ping [^] class.I are Troll
|
|
|
|
|
I want verify if they're in the same lan not if a pc is accessible over lan!
|
|
|
|
|
Hi guys, I would like know how can i check if PC have WOL support and if it is enable or not (in vb or c#).
Somebody can help me??
Thank you men
|
|
|
|
|
write know i am gettin null reference exception due to followin code
Imports System.Xml
Imports System.IO
Public Class TreeView
Dim xNode As XmlNode
Private Sub btnOpenXml_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenXml.Click
populateTreeview()
End Sub
Private Function SelectTextFile() As String
Dim fDialog As New OpenFileDialog()
fDialog.Filter = "xml files (*.xml)|*.xml"
fDialog.InitialDirectory = "~\Desktop"
Return If((fDialog.ShowDialog() = DialogResult.OK), fDialog.FileName, Nothing)
End Function
Private Sub populateTreeview()
Try
'Just a good practice -- change the cursor to a
'wait cursor while the nodes populate
Me.Cursor = Cursors.WaitCursor
'First, we'll load the Xml document
Dim xDoc As New XmlDocument()
xDoc.Load(SelectTextFile())
'Now, clear out the treeview,
'and add the first (root) node
tvXmlTree.Nodes.Clear()
tvXmlTree.Nodes.Add(New TreeNode(xDoc.DocumentElement.Name))
Dim tNode As New TreeNode()
tNode = DirectCast(tvXmlTree.Nodes(0), TreeNode)
'We make a call to addTreeNode,
'where we'll add all of our nodes
addTreeNode(xDoc.DocumentElement, tNode)
'Expand the treeview to show all nodes
tvXmlTree.CollapseAll()
Catch xExc As XmlException
'Exception is thrown is there is an error in the Xml
MessageBox.Show(xExc.Message)
Catch ex As Exception
'General exception
MessageBox.Show(ex.Message)
Finally
'Change the cursor back
Me.Cursor = Cursors.[Default]
End Try
End Sub
Private Sub addTreeNode(ByVal xmlNode As XmlNode, ByVal treeNode As TreeNode)
Dim tNode As TreeNode
Dim xNodeList As XmlNodeList
If xmlNode.HasChildNodes Then
'The current node has children
xNodeList = xmlNode.ChildNodes
For x As Integer = 0 To xNodeList.Count - 1
'Loop through the child nodes
xNode = xmlNode.ChildNodes(x)
treeNode.Nodes.Add(New TreeNode(xNode.Name))
tNode = treeNode.Nodes(x)
addTreeNode(xNode, tNode)
Next
Else
'No children, so add the outer xml (trimming off whitespace)
'treeNode.Text = xmlNode.OuterXml.Trim()
' treeNode.Text = xmlNode.LocalName.Trim()
End If
End Sub
Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
tvXmlTree.Refresh()
End Sub
Private Sub tvXmlTree_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvXmlTree.AfterSelect
'xNode = DirectCast(tvXmlTree.SelectedNode.Tag, XmlNode)
'Me.txtContent.Text = xNode.InnerXml
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnDeleteNode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteNode.Click
tvXmlTree.SelectedNode.Remove()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtContent.Text = String.Empty
txtXml.Text = String.Empty
End Sub
End Class
the above is my code
in this block i am getting object null reference exception
Private Sub tvXmlTree_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvXmlTree.AfterSelect
'xNode = DirectCast(tvXmlTree.SelectedNode.Tag, XmlNode)
'Me.txtContent.Text = xNode.InnerXml
End Sub
i am unable to figure out.can anybody share u r views regarding this issue hw to clarify this
Thanks & Regards
SANDEEP ADEMhi
|
|
|
|
|
1. Format the code using "pre" tags.
2. Don't post entire code. Just post the relevant parts.
3. Something is null in your code while you try to use it. Debug and check."No matter how many fish in the sea; it will be so empty without me." - From song "Without me" by Eminem
|
|
|
|
|
sorry here is the code
Private Sub tvXmlTree_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvXmlTree.AfterSelect
xNode = DirectCast(tvXmlTree.SelectedNode.Tag, XmlNode)
Me.txtContent.Text = xNode.InnerXml
End Sub
here i am using treeview control i had to get the xml from node node selected i am getting null reference exception at the
innerxml
Thanks and regards
SANDEEP ADEMhi
|
|
|
|
|
If that cast is working properly and XmlNode is getting created properly. "No matter how many fish in the sea; it will be so empty without me." - From song "Without me" by Eminem
|
|
|
|