borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (SQL SERVER 2000 with Conditional select Statement)Next Topic (SDK for APC and MGE ups) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Button to save data to SQL Server
Poster Message
dpa123
Level: Trainee

Registered: 19-05-2007
Posts: 1

icon Button to save data to SQL Server

Hi,

I am only new and trying to build a simple application in VB5. I can create a datatable with a dataform from the SQL database that part is fine. I can't seem to create a button to insert data from a textbox to the database though. this is one of the attempts i have made:

    Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
        INSERT INTO users VALUES (textbox2.value)
    End Sub

The problem is it says that Insert & Into are not declared. and that users (the name of the table) needs a valid expresion.

Can you please help me.

19-05-2007 at 12:26 AM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: Button to save data to SQL Server

Hi,
This doesn't appear to be VB5.. more like VS.Net 2005.
Suggest you read on data connectivity using ADo.NET


____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

14-06-2007 at 11:47 AM
View Profile Send Email to User Show All Posts | Quote Reply
Bharathi
Level: Scholar

Registered: 11-04-2005
Posts: 31
icon Re: Button to save data to SQL Server

Hi,



Inserting a new record, updating and deleting a record using the Execute command.

We can use the SQL Insert statement to issue a command that will add a new record in a data source.

Option Explicit
Dim CN As Connection
Dim comobj As Command

Private Sub Form_Load()
Set CN = New Connection
Set comobj = New Command

With CN
.ConnectionString = “Integrated Security=SSPI;Initial Catalog=FinAccounting;Data Source=SYS1”
.Provider = “SQLOLEDB”
.Open
End With
With comobj
.ActiveConnection = CN
.CommandText = “INSERT INTO AccountsTable(AccountCode,AccountName,AccountCat) values(‘C001’,’Creditor1',’1')”
.Execute
End With
End Sub

Updating Records

You can use the SQL Update statement to issue a command that changes a record or group of records.

Option Explicit
Dim CN As Connection
Dim comobj As Command

Private Sub Form_Load()
Set CN = New Connection
Set comobj = New Command

With CN
.ConnectionString = “Integrated Security=SSPI;Initial Catalog=FinAccounting;Data Source=SYS1”
.Provider = “SQLOLEDB”
.Open
End With

With comobj
.ActiveConnection = CN
.CommandText = “UPDATE AccountsTable SET AccountName =’Main Creditor1' WHERE AccountCode=’C001'”
.Execute
End With

End Sub

Deleting a Record using Execute command

You can use the SQL Delete statement to issue a command that deletes a record.

Option Explicit
Dim CN As Connection
Dim comobj As Command

Private Sub Form_Load()
Set CN = New Connection
Set comobj = New Command

With CN
.ConnectionString = “Integrated Security=SSPI;Initial Catalog=FinAccounting;Data Source=SYS1”
.Provider = “SQLOLEDB”

.Open
End With
With comobj
.ActiveConnection = CN
.CommandText = “DELETE FROM AccountsTable WHERE AccountCode=’c001'”
.Execute
End With
End Sub

Database programming using Visual basic 2005

08-08-2007 at 06:35 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : VB General : Button to save data to SQL Server
Previous Topic (SQL SERVER 2000 with Conditional select Statement)Next Topic (SDK for APC and MGE ups) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder