How to insert data from values of textbox into a table

Insert the values of 12 textbox in fields of sql server table

Page 1 of 1

1 Replies - 32700 Views - Last Post: 09 November 2009 - 01:54 AM Rate Topic: -----

#1 mihaispr  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 114
  • Joined: 29-September 09

How to insert data from values of textbox into a table

Posted 07 November 2009 - 09:24 AM

Hi everyone and thanks for reading my question! This is my first post on the visual basic 6 forum!

Please look to my source attached and download it and please read carefully my post!

Now I will explain what I've done and what I don't know how to do with details.

I have done a gui using visual basic6 which provides me entering datas in textbox.

I have two forms.

Form1 has 2 buttons (the button left makes the link with form2 and the second button exits the form1).


Now on Form2 I have:

12 labels
12 textboxes

and 2 buttons :

Urmatoarea Inregistrare - deletes all the content of my formular that contains 12 labels and 12 textbox so it deletes the content of my textboxes every time I entering text in the 12 textboxes. When I press the button Urmatoarea Inregistrare automatically the 12 textboxes becomes empty.

Until now everything it's perfect.


The thing I want to do is to implement the code of the button Salveaza date. (here is my problem)


I complete the fields in the 12 textbox and when I press the button Salveaza Date I want to complete the structure from this table created with SQL Server:


CREATE DATABASE ParcAuto

CREATE TABLE FoaieParcursMasina
(IdFoaie int PRIMARY KEY NOT NULL,
DataFoaieParcurs datetime,
IdMasina int,
DataOraPlecare datetime,
DataOraSosire datetime,
NumeSofer varchar(255),
LocalitatePlecare varchar(255),
LocalitateSosire varchar(255),
KM int,
CombustibilConsumat int
MotivDeplasare varchar(255),
MarfaTransportata varchar(255),
Utilizator varchar(255)
)




So I want to insert first row in table FoaieParcursMasina when I complete the 12 values of my textboxes that lies on form2 of my vb6 form gui (except combustibilconsumat that is not in my vb form as you can see) so that he knows when I press the button Salveaza Date to save my first 12 values of my vb form into my table FoaieParcursMasina (done with CREATE TABLE).

I don't want to insert rows into table FoaieParcursMasina using SQL Server and INSERT INTO clause! I want to insert the datas provided in my 12 textboxes to the fields of my table in SQL Server . The labels are identically with field of the table of SQL Server FoaieParcursMasina as you can see. So everytime the user completes the fields in textbox(IdFoaie,etc) the fields are completed in my sql server table.
So the container of Label1 IdFoaie (which is listbox if I type 1) in IdFoaie field(first field from sql server table FoaieParcursMasina) to be completed automatically with 1 when I press the button Salveaza date from vb6 gui.

Also when I complete the rest of the textboxes the label has the same name as the field in my table if you look .



I want to insert rows when I complete the 12 values from my textbox and I press the button Salveaza Date from my vb6 gui.

I attach here the full project:


http://www.4shared.c..._6_project.html




Here is the DDL for the table that I've created with SQL Server. When I press the button Salveaza Date all the datas contained by the textboxes of my vb6 form will be automatically completed in my table FoaieParcursMasina of SQL Server.

Hope I detailed well my problem (so I want to insert rows from vb6 to


CombustibilConsumat will not be completed it will remain a cell empty in table FoaieParcursMasini of SQL Server, I haven't CombustibilConsumat in my form vb6 as you can see. (so it's the only field I haven't put in my form vb6 for some reasons.

As you can see the name of labels are the same of the fields of FoaieParcursMasina that is created in SQL Server using CREATE TABLE command.

Hope I detailed well my problem!

Here's the code tried in Salveaza Date of Form2:

Private Sub Command2_Click(Index As Integer)
'Imports System.Data
'Imports System.Data.SqlClient
Public Class account
'conexiune -variable used for connection with database
'comandasql - variable for sql query to insert values from textboxes in field of table 'FoaieParcursMasina
'citestedate variable used for readdata
'ra variable used for  a new inserted row in the table (when I delete the containing of textboxes and complete again the 12 textboxes for the second row and when I press button Salveaza Date it adds the second row to my table). 

	Dim conexiune As SqlConnection
	Dim comandasql As SqlCommand
	Dim citestedate As SqlDataReader
Dim ra As Integer 'pt.un rand nou introdus

		conexiune = New SqlConnection("server=localhost;uid=mihaispr;pwd=mihai;database=ParcAuto")
		conexiune.Open()
	  comandasql = New SqlCommand("insert into FoaieParcursMasina([IdFoaie],[DataFoaieParcurs],[IdMasina],[DataOraPlecare],[DataOraSosire],[NumeSofer],[LocalitatePlecare],[LocalitateSosire],[KM],[MotivDeplasare],[MarfaTransportata],[Utilizator]) values ('" & Text1.Text & "','" & Text2.Text & "','" & Text3.Text & "','" & Text4.Text & "','" & Text5.Text & "','" & Text6.Text & "','" & Text7.Text & "','" & Text8.Text & "','" & Text9.Text & "','" & Text10.Text & "','" & Text11.Text & "','" & Text12.Text & "')", conexiune)
			   mycommand.ExecuteNonQuery()
		MessageBox.Show ("New Row Inserted" & ra)
		conexiune.Close()
	End Sub
End Class
End Sub




What I want the value types by user in textbox1 (text1.text) to be added to IdFoaie column of table FoaieParcursMasina from sql server, then
value typed by user in vb6 form in textbox2 so text2.text to be added in DataFoaieParcurs from table FoaieParcursMasina in sql server, value typed by user in vb6 form in textbox3 so text3.text to be added in IdMasina field from table FoaieParcursMasina in sql server.

And so on.

On every press of the button it insert rows in table FoaieParcursMasina (so all textboxes must be completed).

I gave above the code I don't know what I'm missing truly.


Best wishes,

Michael

This post has been edited by mihaispr: 07 November 2009 - 11:09 AM


Is This A Good Question/Topic? 0
  • +

Replies To: How to insert data from values of textbox into a table

#2 mihaispr  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 114
  • Joined: 29-September 09

Re: How to insert data from values of textbox into a table

Posted 09 November 2009 - 01:54 AM

I come back with my old post!

How I can make a formular for user inserts data and when pressing button Salveaza Date will be inserted the values from 12 textboxes in fields (columns) of my table FoaieParcursMasina in SQL Server?


Any ideas please?

I have implemented also the button SalveazaDate it's Command2_Click on Form2 but I really don't know what I'm wrong:

http://www.dreamincode.net/forums/style_images/dic2.1.6b/folder_rte_images/list.gif
Here's the code tried in Salveaza Date of Form2:

CODE

Private Sub Command2_Click(Index As Integer)
'Imports System.Data
'Imports System.Data.SqlClient
Public Class account
'conexiune -variable used for connection with database
'comandasql - variable for sql query to insert values from textboxes in field of table 'FoaieParcursMasina
'citestedate variable used for readdata
'ra variable used for  a new inserted row in the table (when I delete the containing of textboxes and complete again the 12 textboxes for the second row and when I press button Salveaza Date it adds the second row to my table).

	Dim conexiune As SqlConnection
	Dim comandasql As SqlCommand
	Dim citestedate As SqlDataReader
Dim ra As Integer 'pt.un rand nou introdus

		conexiune = New SqlConnection("server=localhost;uid=mihaispr;pwd=mihai;database=ParcAuto")
		conexiune.Open()
	  comandasql = New SqlCommand("insert into FoaieParcursMasina([IdFoaie],[DataFoaieParcurs],[IdMasina],[DataOraPlecare],[DataOraSosire],[NumeSofer],[LocalitatePlecare],[LocalitateSosire],[KM],[MotivDeplasare],[MarfaTransportata],[Utilizator]) values ('" & Text1.Text & "','" & Text2.Text & "','" & Text3.Text & "','" & Text4.Text & "','" & Text5.Text & "','" & Text6.Text & "','" & Text7.Text & "','" & Text8.Text & "','" & Text9.Text & "','" & Text10.Text & "','" & Text11.Text & "','" & Text12.Text & "')", conexiune)
			   mycommand.ExecuteNonQuery()
		MessageBox.Show ("New Row Inserted" & ra)
		conexiune.Close()
	End Sub
End Class
End Sub




Here is the source it's attached here even if it says 0mb: (with Salveaza Date button where I have problems to my question -this is the reason I started the topic)

http://new1.flyuploa...byxJfDnm9CxtIKe

Without integrating the code on button Salveaza Date all is fine as I want here is the first part: (here are not problems , problems appear in my project only in implementing code of button Salveaza Date)

http://www.4shared.c..._6_project.html


MY problem is in the Salveaza Date button to send the datas completed in textbox via the fields of my table FoaieParcursMasina.

Hope you'll have installed Visual Basic 6 in order to run application and help me!

Best regards,

Here are the details of my project explained:


Michael

Attached File(s)


This post has been edited by mihaispr: 09 November 2009 - 03:41 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1