|
Thank for quick reply !
I will chance my design.
Bests regards
|
|
|
|
|
You cannot do this and even if you could there's no point.
Separate your application logic to at least 4 different layers:
- database
- data access layer (the only layer that has to use OracleConnection)
- business logic layer
- UI layer
The layers communicate only with the layer above or underneath so the UI layer does not communicate with DAL and certainly not with the database.
There are several good walkthroughs and articles about this in the internet.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Thank for quick reply !
I will chance my design.
Bests regards
|
|
|
|
|
If ds.HasChanges Then
ds = New DataSet("Database")
Dim dsChanges As DataSet = ds.GetChanges()
Dim updateSQL As String = ("UPDATE CourseLearningOutcomeAssignment SET CoverageExtentID = ? WHERE LearningOutcomeID = ? AND CourseID =?")
da = New OleDbDataAdapter
Dim updateCmd As New OleDbCommand
updateCmd.Parameters.Add("CoverageExtentID", OleDbType.VarChar)
updateCmd.Parameters.Add("LearningOutcomeID", OleDbType.Integer)
updateCmd.Parameters.Add("CourseID", OleDbType.Integer)
updateCmd.Parameters("CoverageExtentID").Value = 2
updateCmd.Parameters("LearningOutcomeID").Value = 1
updateCmd.Parameters.Add("CourseID", OleDbType.Integer)
updateCmd.Parameters("CoverageExtentID").SourceColumn = "CoverageExtentID"
updateCmd.Parameters("LearningOutcomeID").SourceColumn = "LearningOutcomeID"
updateCmd.Parameters("CourseID").SourceVersion = DataRowVersion.Original
myConnection.Open()
da.Fill(ds, "viewcoursedata") <----- stops at this line of code.... with the error msg "The SelectCommand property has not been initialized before calling 'Fill"
DataGridView2.DataSource = ds.Tables("viewcoursedata")
da.Update(dsChanges, "viewcoursedata")
ds.AcceptChanges()
If updateCmd.ExecuteNonQuery() Then
MsgBox("Updated Successfully")
Else
MsgBox("Not updated Successfully")
End If
myConnection.Close()
The problem is when we try to update the datagrid with information weve entered it doesnt send it to the database, then it has an error at the line above.
Any help would be great! project due tonight!
|
|
|
|
|
Where to begin...
First you appear to be mixing up two completely different approaches to updating a database.
Second, you are using a dataset object, which contains ready methods for select, insert and update, and then you try to create the update statement by hand, run it through a OleDbCommand, which you then not connect to the data adapter, which you then expect to execute the OleDbCommand, by calling its fill method, which executes the select statement.
Third, you check whether your dataset has changes and then, when it does, you empty it by assigning it to a new empty dataset.
Fourth, etc, etc, etc.
So, not to leave you hanging, try to go through the following steps and rewrite your code:
1. when you created the OleDataAdapter, you supposedly wrote some select statement.
2. when you finished creating the OleDataAdapter the designer should have created the necessary update and insert statements for you.
3. you created a dataset and bound it to the OleDataAdapter.
4. you probably have a button or something that will execute OleDataAdapter1.Fill(DataSet1, "TableName"). This executes the select statement
5. your datagrid shows the contents of the dataset because you bound it to the dataset.
6. the user makes changes in the datagrid. The dataset bound to the datagrid records the changes (automatically).
7. you probably have a button or something that will execute the code you posted.
8. Completely forget your code. Writing entirely new code will be easier than correcting this mess.
9. use
OleDataAdapter1.Update(DataSet1) instead.
Good luck,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hi
I was just wondering if anyone can help me with my question. i just started vb about a month ago and i'm trying validate data that is being input into a textbox in my calculator. i only want numbers and nothing else. But i can't figure out the parameters that i'm suppose to set for check if the input is valid or.
thank you
|
|
|
|
|
try following
Private Sub textbox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles textbox1.KeyPress, txtFuelCostPerGallon.KeyPress<br />
If Not (Char.IsControl(e.KeyChar) Or Char.IsNumber(e.KeyChar)) Then<br />
e.Handled = True<br />
End If<br />
End Sub
hope this helps
|
|
|
|
|
The answer given previously is working, but an alternative could be to use MaskedTextBox and to define the Mask property.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
hi
Dave Kreskowiak, the below coding didnot work, i am using sql server 2000 with vb.net 2003 is that the resaon?
TextBox2.Text = String.Format("{0} {1}", dr.columnName.Value, dr.columnName.Value) ??
i am using an instance of the class Dataset2.CASHIER_INFORow(dim dr As Dataset2.CASHIER_INFORow)
kewyn
|
|
|
|
|
OK. Don't vote me down for supplying a suggestion that didn't work. It was just that, not a guarantee that you could just copy'n'paste the code and whalaa, it works...
And reply to the previous message. Don't start a new thread. This will keep all the related posts together.
kewyn wrote: dim dr As Dataset2.CASHIER_INFORow
So let's see the exact code your using. At this point, I'm just guessing at what you're using and looking at.
|
|
|
|
|
hi
sorry if i sounded that way, i am just tired of this not working
Public Class form1
Inherits System.Windows.Forms.Form
Dim Reader As SqlClient.SqlDataReader
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents SqlCon As System.Data.SqlClient.SqlConnection Friend WithEvents SqlDataAdapter1 As System.Data.SqlClient.SqlDataAdapter
Friend WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents DataSet2 As logintrial.DataSet2
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.SqlCon = New System.Data.SqlClient.SqlConnection
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.DataSet2 = New logintrial.DataSet2
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.DataSet2, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.DataSource = Me.DataSet2.CASHIER_INFO
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(48, 112)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(296, 96)
Me.DataGrid1.TabIndex = 0
'
'SqlCon
'
Me.SqlCon.ConnectionString = "workstation id=KEWYN;packet size=4096;integrated security=SSPI;data source=KEWYN;" & _
"persist security info=False;initial catalog=343344"
'SqlDataAdapter1
'
Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
Me.SqlDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "CASHIER_INFO", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("CashierId", "CashierId"), New System.Data.Common.DataColumnMapping("Cashier_Firstname", "Cashier_Firstname"), New System.Data.Common.DataColumnMapping("Cashier_Lastname", "Cashier_Lastname")})})
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "SELECT CashierId, Cashier_Firstname, Cashier_Lastname FROM CASHIER_INFO"
Me.SqlSelectCommand1.Connection = Me.SqlCon
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(232, 192)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(56, 56)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(96, 24)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(104, 20)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = ""
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(96, 56)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(160, 20)
Me.TextBox2.TabIndex = 3
Me.TextBox2.Text = ""
'
'DataSet2
'
Me.DataSet2.DataSetName = "DataSet2"
Me.DataSet2.Locale = New System.Globalization.CultureInfo("en-US")
'
'form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(368, 266)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.DataGrid1)
Me.Name = "form1"
Me.Text = "login"
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.DataSet2, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Dim key As BindingManagerBase
Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.SqlDataAdapter1().Fill(Me.DataSet2) 'fill the data adapter with the dataset
Me.TextBox1().Text() = ""
Me.TextBox1().PasswordChar() = "*"
key = Me.BindingContext(DataSet2, "cashier_info")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'If (Me.TextBox1.TabIndex <> -1 Or Me.CompanyComboBox.SelectedIndex <> Nothing) Then
Try
'Dim index As Integer = Me.CompanyComboBox.SelectedIndex
Dim dr As DataSet2.CASHIER_INFORow
'If Reader.Read() Then
'Me.TextBox2().Text() = Me.TextBox1.Text
Me.TextBox2().Text() = String.Format("{0}{1}", dr.CashierId)
'End If
Catch
MessageBox.Show("DID NOT WORK")
Me.Close()
End Try
End Sub
End Class
|
|
|
|
|
Oh boy, where do I begin...
kewyn wrote: Me.SqlDataAdapter1().Fill(Me.DataSet2) 'fill the data adapter with the dataset
First, this doesn't do what your comment says it does. It's just the opposite. The SqlDataAdapter fills a dataset with a copy of the record retrieve from the database.
Next, for what your code is implying, you don't need the BindingContext. So remove that line.
In your Button1_Click handler, you're misunderstanding so many concepts, from OOP to Data Sets to navigation in the data. There's just too much material to cover to fit it in a forum post. Simplify this. Just start by getting the data in your dataset shown in a textbox. Nothing more.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' It look like your SQL statement returns a single record set. This means just one table of records.
' You need to enumerate through the DataRow collection of the DataTable object in your DataSet.
' Get the individual values from each column in the row and format them for output to a String.
Dim message As String = String.Empty
For Each dr As DataRow In DataSet2.Tables(0).Rows
message = message & String.Format("{0}: {1} {2}", dr("CashierId").ToString, dr("Cashier_Firstname").ToString, dr("Cashier_Lastname").ToString)
Next
TextBox1.Text = message
End Sub
Seriously, pickup a book on VB.NET for beginners. That should help you understand the basics of OOP and clear up the misconceptions you have as shown by your code.
|
|
|
|
|
Also:
kewyn wrote: Catch
Don't catch the exception and throw it away. It usually contains informaiton that is helpful in finding the problem.
In framework 1.x a catch without specifying the exception type could be used to catch non-framework exceptions. In framework 2 they are always wrapped in a framework exception, so you should always at least specify the type Exception .
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
How do you get the rectangular coordinates for Bookmarks for an existing Word.doc?
|
|
|
|
|
hi!
I am trying to display my sql data in a textbox by using the following code; this is after i have made connectiions using sqlconnection with sqldataAdapter with also a dataset
the problem code is:
sqldataAdapter
dim dr as Dataset2.CashierRow
me.TextBox2().Text()=dr.CashierId.toString
|
|
|
|
|
kewyn wrote: me.TextBox2().Text()=dr.CashierId.toString
That's not going to work. At best, you'll get "System.Data.DataRow" in the Textbox. You have to write the code that takes each row in the datatable in your dataset and formats the data in each column of that row into whatever form you need. The DataSet class doesn't know anything about how to format your data and doesn't know how to convert it's tables into formatted text strings. It's not supposed to know.
You also don't need to specify Me, and don't need to put the parenthesis after each object or property name.
TextBox2.Text = String.Format("{0} {1}", dr.columnName.Value, dr.columnName.Value)
|
|
|
|
|
I am truly stuck on this and I need despriate help with this. I have posted on MSDN and on VBforums and have no responce. I seriously need this done and I have no idea how to do it.
I am continually throwing around Ideas on how to install printer on LPR port. Here are the givens:
Port: LPR
Server providing LPD: at-cetus.ad.ufl.edu
Queue Name: CSE-211-CLQ
Driver Name: Xerox Phaser 7760GX PS
INF File Name: 7760.inf
I have tried using the registry edits to create the port and that did not work (or I have done it wrong). I have tried NshNetwork:
Code:
WshNetwork.AddWindowsPrinterConnection("\\at-cetus.ad.ufl.edu\CSE-211-CLQ", "Xerox Phaser 7760GX PS", "LPR")
However in NT and Later the LPR is ignored and I can't figure out how to get it to point to the correct inf file and crate the port. I have tried
Shell("rundll32 printui.dll, PrintUIEntry /if /b ""test_1/"" /f ""C:\7760.inf\"" /q /r ""at-cetus.ad.ufl.edu:CSE-211-CLQ/"" /m ""Xerox Phaser 7760GX PS"" /z /u")
However I can't seem to get that to work either.
Lastly I have tried Prnport.vbs as so:
Code:
cscript prnport.vbs -a -r cse-211-clq -h at-cetus.ad.ufl.edu -o lpr -q CSE-211-CLQ
But the Vista machine does not have that and I am not even sure about XP.
I am looking at WMI, however I am completely lost. PLEASE HELP! What am I doing wrong???
|
|
|
|
|
I haven't done this and I can't test it since I don't have any LPR servers around, but I think the command is:
cscript prnport.vbs -a -s serverName -r LPR -q queueName
|
|
|
|
|
However prnport.vbs is non-existent in Vista.
|
|
|
|
|
I have been searching the web high and low for anything that tells me if and how I can take a pdf and insert an image in a certain area on the document.
Does anyone know of a way to do this?
Thank you.
|
|
|
|
|
Youneed a third party PDF library to do this. Exactly how you do it depends on the library that you use. Consult it's documentation. You might want to look at this list[^] for some libraries.
|
|
|
|
|
I have the following code which works if ran on the server:
dim strProcess = "D:\Application\test.exe"
Process.Start(strProcess)
If I do this it won't work:
dim strProcess = "\\ServerName\Application\test.exe"
Process.Start(strProcess)
I can run this (\\ServerName\Application\test.exe) manually on the server, but if the service application I wrote tries to start the process, nothing happens?
Why? Any suggestions?
Lost in the vast sea of .NET
|
|
|
|
|
You could try shelling to the program, or declaring the process?
Dim sysPath As String = \\ServerName\Application\test.exe
Shell(syspath, AppWinStyle.NormalFocus, True)
Declare process
Dim udtProcess As Process = New Process
udtProcess.Start(strProcess)
Any suggestions, ideas, or 'constructive criticism' are always welcome.
|
|
|
|
|
Got zinged on the previous reply..............but don't know why. Give some constructive criticism so that we can all learn - thanks!
Any suggestions, ideas, or 'constructive criticism' are always welcome.
|
|
|
|
|
It's not clear where the code is stored and where it's supposed to be running. If I understand you correctly, your VB.NET code is running on a workstation, loaded from a local (non-network) source and it's trying to launch another executable from a network source?? Correct?? What type of .EXE is this second executable?? Is it a .NET app?? (Yes, it matters!)
|
|
|
|
|