|
One way would be to issue INSERT commands, using Sql. Another way would be using the TableAdapters. Both approaches are described here[^].
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
sorry.. still cant understand how it works.
i have a html table where there are 3 columns studentID,studentName, courseName. There ada 10 rows of textbox for each column. Can u explain how can i use the one that u gave me? I'm not using gridview because my data doesn't exist in the sql table yet. Hope my explanation is clear because my english is not that good.. TQ for the reply... been waiting every minutes for reply
|
|
|
|
|
zaimah wrote: sorry.. still cant understand how it works.
i have a html table where there are 3 columns studentID,studentName, courseName. There ada 10 rows of textbox for each column. Can u explain how can i use the one that u gave me?
That explanation would not fit in a single post.
zaimah wrote: I'm not using gridview because my data doesn't exist in the sql table yet.
You'd need to CREATE TABLE before the INSERT . Both are done using Sql, a separate language with it's own syntax. The other method that's being described in the documentation, is the TableAdapter-approach, where the framework generates these commands on your behalf.
zaimah wrote: been waiting every minutes for reply
As opposed to waiting, find yourself a tutorial, an article, anything that gets you moving in the right direction. It might take a few days before you get a satisfactory answer.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
sorry, maybe my explanation is not clear.
I already have a table "student". And i have a web form where the lecturer can insert a list of new student. I cannot use gridview not because the table doesn't exist, just the data does not exist yet until the lecturer key-in the data.
i know how to use sqldataAdapter to retrieve value from sql table and put it in a textbox. But that is if the data exist. Will try to look for tableadapter.
Sorry again, i waited and at the same time been searching for solution all over the place for any articles related to my problem.
TQ for your reply..
modified 31-Oct-12 9:19am.
|
|
|
|
|
zaimah wrote: I already have a table "student". And i have a web form where the lecturer can insert a list of new student. I cannot use gridview not because the table doesn't exist, just the data does not exist yet until the lecturer key-in the data.
You'd also need a list that contains the students that are linked to a course, and execute insert-commands to fill that. It also means that the student will have to exist, before this list can be saved.
zaimah wrote: i know how to use sqldataAdapter to retrieve value from sql table and put it in a textbox. But that is if the data exist.
That's an update. You'll need something similar for an insert.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Its a bit confusing rite now for me. The lecturer job is to register the student to the table "student". What do u mean by the student will have to exist before the list can be save? Do u mean i have to type manually to the table "student"?
Been trying to find Insert from html table to sql table but keep on seeing from sql table to html table...
Can tableadapter used for webform?
|
|
|
|
|
zaimah wrote: The lecturer job is to register the student to the table "student". What do u mean by the student will have to exist before the list can be save? Do u mean i have to type manually to the table "student"?
The list you are trying to save is a combination of the student, and some other record. Before you can save anything that's linked to a student-record, the student-record must exist in the database.
So, first the student is "inserted", then the rest.
zaimah wrote: Been trying to find Insert from html table to sql table but keep on seeing from sql table to html table...
Data is seldom saved in the same way as it is presented. Can you list the other tables that you have besides the student-table?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
that is what im trying to do.. Insert the student.. How can i do that? Insert a list of student? after that, it would be easier for me to use UPDATE because the student exist in the student table.
I have table for student so i can set their course in table course.
|
|
|
|
|
You don't insert a list, but a record; each record is an item in the list. You'd need to execute an insert-command (yup, still), something similar to this;
Public Sub DoInsert()
Using connection As New SqlConnection(connectionString)
Dim command As SqlCommand = connection.CreateCommand()
command.Connection.Open()
command.CommandText = "INSERT INTO [studenttablename] (StudName, StudAge) VALUES @StudName, @StudAge)"
command.Parameters.AddWithValue("@StudName", "Goku")
command.Parameters.AddWithValue("@StudAge", "9000+")
command.ExecuteNonQuery()
End Using
End Sub
Do that for each item, and the list is "inserted" in the table.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
is there a way for me to insert all using this coding? lets say i have 10 record, how can i use this code to insert each record that i key-in? i want to insert 10 or more records at a time. I manage to UPDATE multiple record using one button on grid view.
But for INSERT, i can only manage to INSERT record one by one. Is there a way for me to INSERT lets say 10 records at a time?
|
|
|
|
|
zaimah wrote: is there a way for me to insert all using this coding?
Yes, by executing that code ten times. If it needs to be a single action, it'd be wrapped in a transaction.
Uploading a list is usually done when importing large text-files - it's called a batch insert.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
|
Hi,
I am recently using SQL for a project of my own. I came across this post and thought I might be able to offer some input. For example, in my team group is creating a database.
There is a way to insert multiple rows into a table in SQL without having to insert them individually. You could formulate the data to be inserted as select statements for multiple list row entries, but I believe for this to be accomplished you may have to do two stages:
1)Put the data into a temporary table
2)Insert from that table.
Live Support Software for Business
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 8:41am.
|
|
|
|
|
Hi,
Does it has a tool to know the memory occupied by a form in a VB application?
Thanks,
Claude
|
|
|
|
|
Gagnon Claude wrote: Does it has a tool to know the memory occupied by a form in a VB application?
Various companies supply memory-profilers, or, one could use the CLR Profiler[^] from Microsoft.
You could also ask the Marshal.SizeOf[^] the form. Take in account that embedded objects (such as a Font) might exist once, and not use memory on each property-slot (only the size of a long for a pointer)
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
An utterly pointless question as you haven't specified which aspect of the forum you're talking about.
Are you referring to the memory required to serial the data content of the form?
Serialize the Form itself, just the controls or controls and content)?
How much memory the code behind the Form is taking as the code runs?
...??
|
|
|
|
|
|
Then you'll need a memory profiler, as Eddie linked to.
|
|
|
|
|
I am trying to write a simple WPF application in VB using Vs2010 and SQLExpress 2012, although i am not using any databinding.
The problem is that although i have found lots of examples of how to write code to read data from the database, some of it seems very complex and others real simple.
Now i want to update my DB and add (transaction log) records to it, i cannot find an example that works with my current setup. It can't be that difficult can it?
Class MainWindow
Dim dataEntities As MaxGateEntities = New MaxGateEntities
Dim passno As String
Dim passcnt As Integer
Dim inout As String
Private Sub Enter_Button_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
Dim Passes As ObjectQuery(Of Pass) = dataEntities.Passes
Dim PassTransactions As ObjectQuery(Of Transaction) = dataEntities.Transactions
passno = Me.PassNumber.Text
Dim passQry = From pass In Passes Where pass.PassID = passno Select pass.InOut
passcnt = passQry.Count
For Each item In passQry
inout = item.ToString
Next
End Sub
End Class
|
|
|
|
|
Gerald Connolly wrote: It can't be that difficult can it?
Depends on what you consider to be difficult. There are examples on MSDN that use adapters, but most of the time you'll see UPDATE or INSERT statements. The example for LINQ can be found here[^].
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy,
I have seen that page, but the examples have this line?
Dim db As New Northwnd("…\Northwnd.mdf")
and i don't have one of those. I added a data source using ADO entities and included the appropriate statement as in my code.
|
|
|
|
|
Gerald Connolly wrote: I added a data source using ADO entities and included the appropriate statement as in my code.
That's a wizard that generates code, and I have not worked with the ADO.NET Entities; the documentation is not very helpful either. That's the reason why I'm still using old-fashioned Sql and simple IDbCommands.
I found an example that matches your code here[^], but I haven't succeeded yet in creating a simple console-application that performs an insert.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I'm a novice programmer. I am having problem in connecting a printer "DATECS DPP-250" in my code. I tried to add "PrintDriver.dll"
but it output's like there is some kind of error that THE memory is being corrupted. I've searched a lot forums but still I can't solve it. Please I really need all of your help.
THIS IS THE PROBLEM:
_________________________________________________________
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at PrintDriverNet.Printer.PDSDK_OpenPrinter(Int32 nKernelMode, String strPrinterName)
at PrintDriverNet.Printer.OpenPrinter() in d:\Sources\Projects\Datecs\PrinterUtility\PrintDriverNet\PrintDriverNet.cs:line 471
at Testing.MainForm.buttonRead_Click(Object sender, EventArgs e) in D:\Works\Testing\Testing\MainForm.vb:line 44
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
Testing
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///D:/Works/Testing/Testing/bin/Debug/Testing.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
PrintDriverNet
Assembly Version: 1.0.4652.23888
Win32 Version: 1.0.4652.23888
CodeBase: file:///D:/Works/Testing/Testing/bin/Debug/PrintDriverNet.DLL
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitdebugging="true">
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
___________________________________________________________
AND HERE IS MY CODE:
__________________________________________________________
Imports PrintDriverNet
Public Class Form1
Private Sub buttonRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonRead.Click
Dim printer__1 As New Printer()
Dim msr_params As Integer = Printer.MRPARAM_PREFIX
Dim buffer As Byte() = New Byte(256 * 3 - 1) {}
Dim res As Integer
textBoxTrack1.Text = String.Empty
textBoxTrack1.Update()
textBoxTrack2.Text = String.Empty
textBoxTrack2.Update()
textBoxTrack3.Text = String.Empty
textBoxTrack3.Update()
Try
textBoxTrack1.Text = "Connecting ..."
textBoxTrack1.Update()
textBoxTrack2.Text = "Connecting ..."
textBoxTrack2.Update()
textBoxTrack3.Text = "Connecting ..."
textBoxTrack3.Update()
''-----I can't connect to my printer here in this statement,it crashes
*--> If printer__1.OpenPrinter() < 0 Then
Throw New ApplicationException("Failed to open connection with printer.")
End If
.------''
textBoxTrack1.Text = "Swipe a magnetic card ..."
textBoxTrack1.Update()
textBoxTrack2.Text = "Swipe a magnetic card ..."
textBoxTrack2.Update()
textBoxTrack3.Text = "Swipe a magnetic card ..."
textBoxTrack3.Update()
If checkBoxTrack1.Checked Then
msr_params = msr_params Or Printer.MRPARAM_TRACK1
End If
If checkBoxTrack2.Checked Then
msr_params = msr_params Or Printer.MRPARAM_TRACK2
End If
If checkBoxTrack3.Checked Then
msr_params = msr_params Or Printer.MRPARAM_TRACK3
End If
If (InlineAssignHelper(res, printer__1.ReadMagstripe(10000, msr_params, buffer, buffer.Length))) < 0 Then
Throw New ApplicationException("Failed to read magstripe data.")
End If
textBoxTrack1.Text = "No track selected or available data."
textBoxTrack2.Text = "No track selected or available data."
textBoxTrack3.Text = "No track selected or available data."
Dim i As Integer = 0, j As Integer = -1
While i < res
Select Case buffer(i)
Case &HF1
j = buffer(i)
textBoxTrack1.Text = String.Empty
Exit Select
Case &HF2
j = buffer(i)
textBoxTrack2.Text = String.Empty
Exit Select
Case &HF3
j = buffer(i)
textBoxTrack3.Text = String.Empty
Exit Select
Case Else
Select Case j
Case &HF1
textBoxTrack1.Text += Convert.ToChar(buffer(i))
Exit Select
Case &HF2
textBoxTrack2.Text += Convert.ToChar(buffer(i))
Exit Select
Case &HF3
textBoxTrack3.Text += Convert.ToChar(buffer(i))
Exit Select
End Select
Exit Select
End Select
i += 1
End While
If checkBoxOnPaper.Checked Then
Dim receipt As String = String.Empty
receipt += vbLf
receipt += "Track1: " & textBoxTrack1.Text & vbLf
receipt += "Track2: " & textBoxTrack2.Text & vbLf
receipt += "Track3: " & textBoxTrack3.Text & vbLf
receipt += vbLf & vbLf & vbLf
Dim printBuff As Byte() = System.Text.Encoding.ASCII.GetBytes(receipt)
If printer__1.WritePrinterDirect(printBuff, printBuff.Length) < 0 Then
Throw New ApplicationException("Failed to print data.")
End If
End If
If printer__1.ClosePrinter() < 0 Then
Throw New ApplicationException("Failed to close connection with printer.")
End If
Catch ae As ApplicationException
textBoxTrack1.Text = ae.Message
textBoxTrack2.Text = ae.Message
textBoxTrack3.Text = ae.Message
Finally
printer__1.Dispose()
End Try
End Sub
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
target = value
Return value
End Function
End Class
__________________________________________________________
|
|
|
|
|
What exactly do you mean by "connecting a printer"??
What version of Windows are you running this app on? 32 or 64 bit? Is your app compiled to target AnyCPU, or x86 or x64?? What bitness is the library you're using?
|
|
|
|
|
I mean it's opening port so my code can pass through.
My problem when it goes through this statement, It says that the memory is corrupt because of the "PrintDriver.dll."
___________________________________________________________
If printer__1.OpenPrinter() < 0 Then
Throw New ApplicationException("Failed to open connection with printer.")
End If
___________________________________________________________
Im using 32bit and x86 compilation. Please,If you have an email, I can pass it to you about my program because I can't explain briefly here. So you can see what I mean sir.
|
|
|
|