473,395 Members | 1,680 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,395 software developers and data experts.

Update SQL database using VB code.

27
Hello everyone,

I want to get all records from the "Student" database table where StudentStatus = 'New'' .Find a particular RegDate (2001/02/02) , StudNo ( 200144176) and update it's StudentStatus to "Öld", by clicking a command button ( UpdateDatabase). I'm using SQL2000( Windows Authentication).

and please show me how to connect or retreive that information from the database .

Hope I make sense.
Jan 31 '07 #1
10 44904
hariharanmca
1,977 1GB
Hello everyone,

I want to get all records from the "Student" database table where StudentStatus = 'New'' .Find a particular RegDate (2001/02/02) , StudNo ( 200144176) and update it's StudentStatus to "Öld", by clicking a command button ( UpdateDatabase). I'm using SQL2000( Windows Authentication).

and please show me how to connect or retreive that information from the database .

Hope I make sense.

You can Get it by qrys.....
Jan 31 '07 #2
nosipho
27
You can Get it by qrys.....

Yes, but how do I do that. I want to design program that is going to update the database for me and change the Status from new to old. I need to know what I should write on the Update command button, can you please show me the code. I'm using SQL2005 and vb6
Jan 31 '07 #3
willakawill
1,646 1GB
Hi. You will need a connection object and a sql update statement.
Expand|Select|Wrap|Line Numbers
  1. "UPDATE [Student] SET [StudentStatus] = 'Old' WHERE (([StudentStatus] = 'New') AND (RegDate = 2001/02/02') AND (StudNo = 200144176))"
Jan 31 '07 #4
Killer42
8,435 Expert 8TB
Hi. You will need a connection object and a sql update statement.
Expand|Select|Wrap|Line Numbers
  1. "UPDATE [Student] SET [StudentStatus] = 'Old'
  2.   WHERE (([StudentStatus] = 'New')
  3.   AND (RegDate = 2001/02/02')
  4.   AND (StudNo = 200144176))"
I know this is a convoluted area, but wouldn't one need hashes around the date? Or is that Access only, or what? Hm... guess I'd better go re-read NeoPa's mini-tutorial.

Oops! Just noticed, you've got a spurious (well, at least unmatched) single-quote character after your date. Now underlined
Feb 1 '07 #5
willakawill
1,646 1GB
I know this is a convoluted area, but wouldn't one need hashes around the date? Or is that Access only, or what? Hm... guess I'd better go re-read NeoPa's mini-tutorial.

Oops! Just noticed, you've got a spurious (well, at least unmatched) single-quote character after your date. Now underlined
There you go. Yes the # is for Access only
Feb 1 '07 #6
nosipho
27
There you go. Yes the # is for Access only
Thanks for you responses guys but the problem is, What I need is the code to execute that statement in the database e.g

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Dim conn as ADODB.Connection
  4. Dim rs AS ADODB.Recordset
  5.  
  6. Private sub Form_load()
  7. Set conn = new ADODB.Connection
  8. Set rs = New ADODB.Recordset
  9.  
  10. conn.open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog= TEST ;Data Source=NOCOMP" 
  11.  
  12.  
  13. Private Sub cmdUpdate _Click)
( Then what?) I do'nt know. I've never connected vb using a code I use a data environment.
I need help connecting vb to the database & Update command

I know I'm asking a lot but help me out guys.
Feb 1 '07 #7
willakawill
1,646 1GB
You don't need a recordset for this sql statement
Expand|Select|Wrap|Line Numbers
  1. Dim stSQL As String
  2.  
  3. stSQL = "UPDATE [Student] SET [StudentStatus] = 'Old' WHERE " _
  4. & "(([StudentStatus] = 'New') AND (RegDate = '" & putdatehere & "') " _
  5. & "AND (StudNo = " & putstudentnohere & "))"
  6.  
  7. conn.Execute stSQL
Feb 1 '07 #8
nosipho
27
You don't need a recordset for this sql statement
Expand|Select|Wrap|Line Numbers
  1. Dim stSQL As String
  2.  
  3. stSQL = "UPDATE [Student] SET [StudentStatus] = 'Old' WHERE " _
  4. & "(([StudentStatus] = 'New') AND (RegDate = '" & putdatehere & "') " _
  5. & "AND (StudNo = " & putstudentnohere & "))"
  6.  
  7. conn.Execute stSQL

Ok, I don't need a recordset but what do I need? I have no I idea how / where to write that in my programm. Do I write it under cmdUpdate. I need the whole code to this pleease
Feb 2 '07 #9
willakawill
1,646 1GB
Ok, I don't need a recordset but what do I need? I have no I idea how / where to write that in my programm. Do I write it under cmdUpdate. I need the whole code to this pleease
All the code is here. Yes you should put it in the cmdUpdate onclick event
Feb 2 '07 #10
nosipho
27
All the code is here. Yes you should put it in the cmdUpdate onclick event
Thank you so much for your responses. My program is running so smooth because of you.

Thanks
Feb 5 '07 #11

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

Similar topics

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...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
9
by: Pam Ammond | last post by:
I need the code to update the database when Save is clicked and a text field has changed. This should be very easy since I used Microsoft's wizards for the OleDBAdapter and OleDBConnection, and...
2
by: Joe Fetters via .NET 247 | last post by:
Have googled and read the VS.NET documentation can't seem to getthe answer to the following. Environment: Framework 1.1 VB.NET WinForm Access database Using all automagic tools (DataAdapter...
13
by: abdoly | last post by:
i wrote a code to update datagrid with the datagrid updatecommand but i cant get the updated values after being update that is the code private void DataGrid1_UpdateCommand(object source,...
17
by: Benoit Martin | last post by:
I'm working on a project in VB.net connecting to a SQL Server 2000 database that I can't modify I created a dataset with a schema identical to the DB. When trying to update the DB from the dataset...
5
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I...
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. ...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.