|
You're welcome.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Hello,
I would like to ask how can I show what I have recently updated in my database
I just use textboxe's to show my data but my problem is that I does not show it yet
until I restart my program.Not like my delete command that it immediately affect
what changes I have made in the database.
Problem Conclusion:
How to immediately show changes made after updating the database
For more details below here are my codes:
My Declarations:
Dim con As New OleDb.OleDbConnection
Dim da As New OleDb.OleDbDataAdapter
Dim ds As New DataSet
Dim dt As New DataTable
Dim sSQL As String
Dim maxRows As Integer
Dim inc As Integer
My sub to display my database records to textbox:
Private Sub setRecords()
Try
'set the specific records
txtProduct_ID.Text = dt.Rows(inc).Item("productID")
txtProductName.Text = dt.Rows(inc).Item("productName")
txtProductDescription.Text = dt.Rows(inc).Item("productDescription")
txtProductCategory.Text = dt.Rows(inc).Item("productCategory")
txtProductStatus.Text = dt.Rows(inc).Item("productStatus")
txtProductPrice.Text = dt.Rows(inc).Item("productPrice")
txtProductQuantity.Text = dt.Rows(inc).Item("productQuantity")
datePicker.Text = dt.Rows(inc).Item("productDateAdded")
'disable editing when form in load
txtProduct_ID.Enabled = False
txtProductName.Enabled = False
txtProductDescription.Enabled = False
txtProductCategory.Enabled = False
txtProductStatus.Enabled = False
txtProductPrice.Enabled = False
txtProductQuantity.Enabled = False
datePicker.Enabled = False
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
MY code in update:
con.Close()
Try
con.Open()
Try
'add a new row
Dim Rows As DataRow
Rows = dt.NewRow
Rows.Item("productID") = Val(txtProduct_ID.Text)
Rows.Item("productName") = txtProductName.Text
Rows.Item("productCategory") = txtProductCategory.Text
Rows.Item("productDescription") = txtProductDescription.Text
Rows.Item("productStatus") = txtProductStatus.Text
Rows.Item("productPrice") = Val(txtProductPrice.Text)
Rows.Item("productQuantity") = Val(txtProductQuantity.Text)
Rows.Item("productDateAdded") = datePicker.Text
dt.Rows.Add(Rows)
Catch ex As OleDb.OleDbException
MsgBox(ex.ToString)
End Try
'save changes made to the database
sSQL = "SELECT * FROM productTable"
da = New OleDb.OleDbDataAdapter(sSQL, con)
Dim cb As New OleDb.OleDbCommandBuilder(da)
da.Update(dt)
'move to last records of the database
inc = -1
If inc <> maxRows - 1 Then
inc = maxRows - 1
setRecords()
End If
con.Close()
MsgBox("Records Succesfully Saved")
Catch ex As OleDb.OleDbException
MsgBox(ex.ToString)
End Try
End Sub
my code in delete:
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim a As MsgBoxResult
a = MsgBox("Are you sure you want to delete this Record ?", MsgBoxStyle.YesNo + MsgBoxStyle.Critical, "Deleting Records")
If a = MsgBoxResult.Yes Then
Try
Dim cb As New OleDb.OleDbCommandBuilder(da)
dt.Rows(inc).Delete()
maxRows = maxRows - 1
inc = 0
setRecords()
da.Update(dt)
MsgBox("Records Successfully Deleted")
setRecords()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Else
MsgBox("Deleting Records have been canceled!")
End If
End Sub
Thanks,
dfan23
|
|
|
|
|
All in all, you have Delete, Insert, Update in a class, so you can declare an Event (Modified), and subscribe to it. When it fires, call setRecords sub. In C# it looks as follows:
public event EventHandler<EventArgs> DatabaseDataModified;
protected virtual void OnDatabaseDataModified(EventArgs args)
{
if(DatabaseDataModified != null)
DatabaseDataModified.Invoke(this, args);
}
Call OnDatabaseDataModified method everytime a record is updated in the database.
Subscribe to DatabaseDataModified event and call setRecords sub, once the event handler fires. For a more detailed review check publish/subscribe model.
|
|
|
|
|
I hv to get control reference in thread method let suppose in this example i m setting text lable of text control but it gives exception at Statment TextBox1.Text="DFD"
Exception is
Cross-thread operation not valid: Control 'TextBox1' accessed from a thread other than the thread it was created on.
code is below
Public Class data
Private myUtil As Util = New Util()
Private strSQL As String = ""
Public Sub savedata()
'Label1.Text = "DFDF"
' Dim d As data
TextBox1.Text = "DFDF"
Try
strSQL = "Insert into tbldata(pid,pname,pdesc) values(2, 'abc', 'description1')"
If (myUtil.ExecuteDBCommand(strSQL) = 1) Then
'MsgBox("Account(s) Assigned Sucessfully!")
Else
MessageBox.Show("Could not Save Record!", "Account Information!", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
Catch ex As Exception
End Try
End Sub
Private Sub data_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim t1 As Threading.Thread = New Threading.Thread(AddressOf savedata)
t1.Start()
End Sub
End Class
plz help
|
|
|
|
|
|
great reference!
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
That's exactly why I used it
|
|
|
|
|
I'm looking for a tool or a standard for writing software requirements (SRS) for a .NET application.
Does anyone have any tips on this matter?
|
|
|
|
|
|
I see your point - thanks Mark!
|
|
|
|
|
hii all i want to create a desktop application using csharp .net.
can anybody give me link from where i can learn how to create windows application(project)
,database connectivity etc.plz help.....
|
|
|
|
|
You should be reading a .Net book. Almost all books have samples.
Have a look here.
Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
|
How to display 60 questions with options for an online exam
|
|
|
|
|
Lakshmithangaraj wrote: How to display 60 questions with options for an online exam
Well, you're normally going to have some form of datasource backing this up - be it a database or XML file. You'd have a question with a number of possible answers, some of which would be marked as correct answers and some incorrect. Then you display the questions along with the possible answers - the user chooses what they think is correct and you store their answers. Finally, you'll compare their answers with your reference answers and see how many they got right.
That seems straightforward enough.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
|
I need a sample online quiz application
|
|
|
|
|
Well try google then. Nobody is going to do your homework for you. You have been given a straight forward explanation, so try coding it.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
hi.....
i am doing my final year project in C# integrated with grid.
i have a problem here which is...
i want to connect all computers in my lan network using ip address and need to access the file contents present in them....
i have connected the computers using this coding,
Console.Write("Enter the IPAddress of the file:");
string ipadd = Console.ReadLine();
IPAddress[] ips = Dns.GetHostAddresses(ipadd);
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Console.WriteLine("Establishing Connection to{0}", ipadd);
s.Connect(ips[0], 9001);
Console.WriteLine("Connection Established");
now i want to access the file contents present in that system.is it possible and i would do it through the use of streamreader class........
the important thing is it is not a client-server coding....
it is a single application coding that needs to access another system's file contents...
thanx in advance.
|
|
|
|
|
thivya n wrote: the important thing is it is not a client-server coding
It is by its very nature client/server as you cannot do this without having a listener (aka server) socket on the destination computer.
MVP 2010 - are they mad?
|
|
|
|
|
is it not possible to connect a socket(connected to other system) to a streamreader to access a file contents...
|
|
|
|
|
I think so, take a look at this article[^] here on CodeProject.
MVP 2010 - are they mad?
|
|
|
|
|
the article u mentioned is based on a server and a client.
but the one i require is for a single-ended application......
connection between a socket and a stream......
could u help me with that.....
|
|
|
|
|
I guess in theory, though that is not the problem.
As has been said, creating a socket from machine A to machine B is no good to you if nothing is on the other end of the socket. All sockets require an endpoint for communication, in this case a service on the remote machine that sends you the file content.
If, as it seems, you are writing a single ended application you just need to create a stream reader on the remote file using the UNC path. This of course assumes the network security setup is such that you have access to the file on the remote computer.
|
|
|
|
|
could u help me ur idea explained with an example! please...
also the project i am doing is an integration of grid computing and C# console application, so it is a single-ended application...
the main idea i want to implement is...
1.connect to a remote computer using its ip address from my computer in LAN.
2.specify the path of the file in the remote computer from my computer.
3.read its contents through a stream reader.
4.access its contents using stream writer.
thanks in advance.
|
|
|
|