473,320 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to update database?

32
What the step should I take for if i wanna to update my database?The situation is something like this..I have a "User-Interface" form which to let user to insert data on it,for example is like a textbox.when i insert the data on the textbox,i wanna the data to store into the database if that is a new data while if that is a data that ald stored inside the database,then just need to update it...can give some examples code for me as references?

Thanks!! ;-)
Jun 9 '07 #1
5 1317
nairda
39
What the step should I take for if i wanna to update my database?The situation is something like this..I have a "User-Interface" form which to let user to insert data on it,for example is like a textbox.when i insert the data on the textbox,i wanna the data to store into the database if that is a new data while if that is a data that ald stored inside the database,then just need to update it...can give some examples code for me as references?

Thanks!! ;-)

Hi dyc,

You'll need 1 Command Button (CmdSave) so you can trigger the UPDATE or ADDNEW action from your UI form to your database.
Once you clicked this CmdSave, VB will search for the matching data. If there is no matching data, then VB will save the data as a new data in your database (ADDNEW action). In the contrary, if there's a matching data between your input and your database, VB will be done an UPDATE action to the data.

Expand|Select|Wrap|Line Numbers
  1. Private Sub CmdSave_Click()
  2.     Dim conec As New ADODB.Connection
  3.     Dim rs As New ADODB.Recordset
  4.     conec.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source ='" & App.Path & "mydatabase.mdb'"
  5.     conec.CursorLocation = adUseClient
  6.     conec.Open
  7.  
  8.     rs.Open "select * from STUDENT where STUDENTCODE='" & Text1.Text & "'", conec, adOpenKeyset, adLockOptimistic
  9.  
  10.     If Text1.text = "" Then
  11.         MsgBox "Please fill the Student Code Number", vbCritical,
  12.         Else
  13.           With rs
  14.              ' Search for identical/matching STUDENTCODE
  15.              If rs.RecordCount = 0 then    '---> If there's no identical/matching STUDENTCODE, then save as new data
  16.               .AddNew
  17.              End If
  18.                 !STUDENTCODE = Text1.Text
  19.                 !STUDENTNAME = Text2.Text
  20.                 !STUDENTADDRESS = Text3.Text
  21.                 .Update
  22.           End With
  23.      End If
  24. End Sub

I hope these code will help you get the picture.

NAIRDA
Jun 11 '07 #2
dyc
32
how about if I'm using SQL database in the visual studio 2005?How do I do the connection string and those related command?and do I also need to use tableadapter?
Thanks...
Jun 11 '07 #3
debasisdas
8,127 Expert 4TB
The process is same .

Only thing is that u need to change the connection string.

To do this best way is

1.open notepad.
2.save the file with .UDL extension.
3.then open the file and just follow certain steps (which is so easy).
4. close the file.
5.right click and open with notepad.
6.copy after the first line

u get the connection string for sql-server.

next the process is so simple which u can get from any good material/book
Jun 11 '07 #4
dyc
32
Dim objConnection As SqlConnection = New _
SqlConnection("server=(128-10);database=YY")
Dim objCommand As SqlCommand = New SqlCommand()
Dim objDataAdapter As New SqlDataAdapter()
objDataAdapter.SelectCommand = New SqlCommand()
objConnection.Open()
objCommand.Connection = objConnection
objDataAdapter.SelectCommand.Connection = objConnection
objDataAdapter.SelectCommand.CommandText = "InsertYY"
objDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure
' automatically create update/delete/insert commands
Dim objCommandBuilder As SqlCommandBuilder = New SqlCommandBuilder(objDataAdapter)


when i run this program,it ends up wif an error msg :

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

I have no idea what have happened ...Is there something wrong with my code??
Jun 12 '07 #5
dyc
32
Can we do something like when we click a update button ,then the data we wanna to update is extracted from a long string and I have chopped it into individual string with substring method.
How do I do if i wanna to update the database?
thanks!!
Jun 13 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mark | last post by:
A beginner in this area, I have been able to read a record from a MySQL database and populate an HTML form (wow!). Now, my goal is to allow the user to edit the contents of the form and then...
2
by: Niyazi | last post by:
Hi, I have not understand the problem. Before all the coding with few application everything worked perfectly. Now I am developing Cheque Writing application and when the cheque is clear the...
5
by: Klemens | last post by:
I get SQL30090 reason 18 by trying to do an insert in a federated table and an update in a local table in one transaction Do I have to change some settings to get done or ist this not possible by...
7
by: PC Datasheet | last post by:
Looking for suggestions ---- A database was designed for a national automobile inspection program. In it's simplest form, the database has two tables: TblOwner OwnerID <Year/Make/Model owned...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
0
by: Vijay Balki | last post by:
I am fetching data in DataSet - myDataSet, from a remote database using a Web Service in my VB.NET client..Once I fetch it I store the data in XML file (myXMLFile) using the WriteXML method of the...
8
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. ...
2
by: TJ | last post by:
Hi All, I am having some trouble. I have created a database via the new database option inside VWD2005. Then and table or two. I have been able to perform INSERT and SELECT operations on...
2
by: Miro | last post by:
I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an index - i...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.