473,725 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding data to SQL from form textbox, a variable

Hi all,
I know this is easy, just can't seem to get it. I have a windows form, and
a text box, with a value already in it. I need to add that value to a table.
It's just one value, so the entire row doesn't get filled. I have a
connection and all that stuff.

Private Sub btnPlaceBet_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnPlaceBet.Cli ck
' Dim Myds As Footbet.DStable
' txbxCPwage.Data Bindings.Add("t xbxCPwage", Myds, "TableID.Pa ss")

Just looking for the code to pass this value to the DS.

TIA!
Rudy

Nov 21 '05 #1
6 4427
Rudy,

I do not understand you, therefore I give you 2 answers, if you want to add
it to the databaset table, than you have to create an SQL insert command and
than use an SQLcommand.nonq uery to update your database, that is all.

http://msdn.microsoft.com/library/de...QueryTopic.asp

When you want to add it to an item in a row in a datatable in a dataset than
it can be
ds.tables("thet able").rows(the rownumber)("the Item") = "xxxx"

I hope this helps?

Cor

"Rudy" <Ru**@discussio ns.microsoft.co m>
Hi all,
I know this is easy, just can't seem to get it. I have a windows form,
and
a text box, with a value already in it. I need to add that value to a
table.
It's just one value, so the entire row doesn't get filled. I have a
connection and all that stuff.

Private Sub btnPlaceBet_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnPlaceBet.Cli ck
' Dim Myds As Footbet.DStable
' txbxCPwage.Data Bindings.Add("t xbxCPwage", Myds, "TableID.Pa ss")

Just looking for the code to pass this value to the DS.

TIA!
Rudy

Nov 21 '05 #2
Hi Cor,
Thank you for your input. Let me try to explain a little bit better. I have
an answer to a formula that will show up in textbox1. I have 4 textboxs with
the same situation, except the formula is diffrent for each textbox,
therefore, four diffrent answers. In my table i have a column name textbox1,
2, 3, and 4, to match the information to the form. Anyone of the values in
the textbox need to be placed in the table, just 1 or 2 or 3 or all 4 at any
time. When the ENTER button click_event is fired, it needs to take the
values, put them in the approiate coulmns. I'm using SQL by the way for
this. So I'm not sure if I can specify which row it will go into, because it
really doesn't matter. the info will just keep adding to the next row. I
guess the row number would relate to how many times the ENTER click event is
fired. first click, row 1, second click, row 2. In addition, to make things
more interesting, I need to be able to have 5 client computers that has this
setup, going to one SQL server. The number of clicks would actually be total
number from all five clients. Right now I have column in the table to keep
track of which client is enter the values. But I thought about just make
duplicate tables, for the diffrent clients, not sure which would be better.
The max clients I may have is 100. I hope this make sense. Sorry for
rambling on.
Rudy
"Cor Ligthert" wrote:
Rudy,

I do not understand you, therefore I give you 2 answers, if you want to add
it to the databaset table, than you have to create an SQL insert command and
than use an SQLcommand.nonq uery to update your database, that is all.

http://msdn.microsoft.com/library/de...QueryTopic.asp

When you want to add it to an item in a row in a datatable in a dataset than
it can be
ds.tables("thet able").rows(the rownumber)("the Item") = "xxxx"

I hope this helps?

Cor

"Rudy" <Ru**@discussio ns.microsoft.co m>
Hi all,
I know this is easy, just can't seem to get it. I have a windows form,
and
a text box, with a value already in it. I need to add that value to a
table.
It's just one value, so the entire row doesn't get filled. I have a
connection and all that stuff.

Private Sub btnPlaceBet_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnPlaceBet.Cli ck
' Dim Myds As Footbet.DStable
' txbxCPwage.Data Bindings.Add("t xbxCPwage", Myds, "TableID.Pa ss")

Just looking for the code to pass this value to the DS.

TIA!
Rudy


Nov 21 '05 #3
Hello Rudy,

Your right this is actually easy but a little bit of code writing will be
involved.

First, Are you writing these values to existing records or are you creating
a new record based on these formulas.. Its not a big deal if which one your
doing or if your doing both..

You will need the following

SqlConnection
SqlDataAdapter
SqlCommandBuild er
DataSet
DataRow

Exp..

Dim objSqlConn As SqlConnection
Dim objSqlDa As SqlDataAdapter
Dim objSqlCmdB As SqlCommandBuild er
Dim objSqlDs as New DataSet
Dim objSqlRow as DataRow

objSqlConn = New SqlConnection(S tring of connection)
objSqlConn.Open

Dim strSqlTxt As String = ("Your query statement, usually a SELECT type")
**** Now this can be written in a manner as to return existing records or
where a field = Null so you nothing is returned, but you have a base for
adding new records.****

objSqlDa = New SqlDataAdapter( "strSqlTxt" , objSqlConn)
objSqlCmdB = New SqlCommandBuild er(objSqlDa)
objSqlDa.Fill(o bjSqlDs)

*** This next bit of code is for adding a record and filling the values ****

objSqlRow = objSqlDs.Tables (0).NewRow

With objSqlRow
.Item("TextBox1 ") = TextBox1.Text
.Item("TextBox2 ") = TextBox2.Text
Ect ect ect

End with

objSqlDs.Tables (0).Rows.Add(ob jSqlRow)
objSqlDa.Update (objSqlDs)

****Now if you have a query that is searching for an existing record you can
do the samw but with out adding a new record ****
objSqlRow = objSqlDs.Tables (0).Rows(0)

With objSqlRow

.Item("TextBox1 ") = TextBox1.Text
Ect, ect,ect ect..

End With

objSqlDa.Update (objSqlDs)

Well you might get the idea, if you have any questions feel free to ask...

Best regards,


"Rudy" wrote:
Hi Cor,
Thank you for your input. Let me try to explain a little bit better. I have
an answer to a formula that will show up in textbox1. I have 4 textboxs with
the same situation, except the formula is diffrent for each textbox,
therefore, four diffrent answers. In my table i have a column name textbox1,
2, 3, and 4, to match the information to the form. Anyone of the values in
the textbox need to be placed in the table, just 1 or 2 or 3 or all 4 at any
time. When the ENTER button click_event is fired, it needs to take the
values, put them in the approiate coulmns. I'm using SQL by the way for
this. So I'm not sure if I can specify which row it will go into, because it
really doesn't matter. the info will just keep adding to the next row. I
guess the row number would relate to how many times the ENTER click event is
fired. first click, row 1, second click, row 2. In addition, to make things
more interesting, I need to be able to have 5 client computers that has this
setup, going to one SQL server. The number of clicks would actually be total
number from all five clients. Right now I have column in the table to keep
track of which client is enter the values. But I thought about just make
duplicate tables, for the diffrent clients, not sure which would be better.
The max clients I may have is 100. I hope this make sense. Sorry for
rambling on.
Rudy
"Cor Ligthert" wrote:
Rudy,

I do not understand you, therefore I give you 2 answers, if you want to add
it to the databaset table, than you have to create an SQL insert command and
than use an SQLcommand.nonq uery to update your database, that is all.

http://msdn.microsoft.com/library/de...QueryTopic.asp

When you want to add it to an item in a row in a datatable in a dataset than
it can be
ds.tables("thet able").rows(the rownumber)("the Item") = "xxxx"

I hope this helps?

Cor

"Rudy" <Ru**@discussio ns.microsoft.co m>
Hi all,
I know this is easy, just can't seem to get it. I have a windows form,
and
a text box, with a value already in it. I need to add that value to a
table.
It's just one value, so the entire row doesn't get filled. I have a
connection and all that stuff.

Private Sub btnPlaceBet_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnPlaceBet.Cli ck
' Dim Myds As Footbet.DStable
' txbxCPwage.Data Bindings.Add("t xbxCPwage", Myds, "TableID.Pa ss")

Just looking for the code to pass this value to the DS.

TIA!
Rudy


Nov 21 '05 #4
Thank You DuPont, I will try this tonight and let you know.

Rudy

"DuPont" wrote:
Hello Rudy,

Your right this is actually easy but a little bit of code writing will be
involved.

First, Are you writing these values to existing records or are you creating
a new record based on these formulas.. Its not a big deal if which one your
doing or if your doing both..

You will need the following

SqlConnection
SqlDataAdapter
SqlCommandBuild er
DataSet
DataRow

Exp..

Dim objSqlConn As SqlConnection
Dim objSqlDa As SqlDataAdapter
Dim objSqlCmdB As SqlCommandBuild er
Dim objSqlDs as New DataSet
Dim objSqlRow as DataRow

objSqlConn = New SqlConnection(S tring of connection)
objSqlConn.Open

Dim strSqlTxt As String = ("Your query statement, usually a SELECT type")
**** Now this can be written in a manner as to return existing records or
where a field = Null so you nothing is returned, but you have a base for
adding new records.****

objSqlDa = New SqlDataAdapter( "strSqlTxt" , objSqlConn)
objSqlCmdB = New SqlCommandBuild er(objSqlDa)
objSqlDa.Fill(o bjSqlDs)

*** This next bit of code is for adding a record and filling the values ****

objSqlRow = objSqlDs.Tables (0).NewRow

With objSqlRow
.Item("TextBox1 ") = TextBox1.Text
.Item("TextBox2 ") = TextBox2.Text
Ect ect ect

End with

objSqlDs.Tables (0).Rows.Add(ob jSqlRow)
objSqlDa.Update (objSqlDs)

****Now if you have a query that is searching for an existing record you can
do the samw but with out adding a new record ****
objSqlRow = objSqlDs.Tables (0).Rows(0)

With objSqlRow

.Item("TextBox1 ") = TextBox1.Text
Ect, ect,ect ect..

End With

objSqlDa.Update (objSqlDs)

Well you might get the idea, if you have any questions feel free to ask...

Best regards,


"Rudy" wrote:
Hi Cor,
Thank you for your input. Let me try to explain a little bit better. I have
an answer to a formula that will show up in textbox1. I have 4 textboxs with
the same situation, except the formula is diffrent for each textbox,
therefore, four diffrent answers. In my table i have a column name textbox1,
2, 3, and 4, to match the information to the form. Anyone of the values in
the textbox need to be placed in the table, just 1 or 2 or 3 or all 4 at any
time. When the ENTER button click_event is fired, it needs to take the
values, put them in the approiate coulmns. I'm using SQL by the way for
this. So I'm not sure if I can specify which row it will go into, because it
really doesn't matter. the info will just keep adding to the next row. I
guess the row number would relate to how many times the ENTER click event is
fired. first click, row 1, second click, row 2. In addition, to make things
more interesting, I need to be able to have 5 client computers that has this
setup, going to one SQL server. The number of clicks would actually be total
number from all five clients. Right now I have column in the table to keep
track of which client is enter the values. But I thought about just make
duplicate tables, for the diffrent clients, not sure which would be better.
The max clients I may have is 100. I hope this make sense. Sorry for
rambling on.
Rudy
"Cor Ligthert" wrote:
Rudy,

I do not understand you, therefore I give you 2 answers, if you want to add
it to the databaset table, than you have to create an SQL insert command and
than use an SQLcommand.nonq uery to update your database, that is all.

http://msdn.microsoft.com/library/de...QueryTopic.asp

When you want to add it to an item in a row in a datatable in a dataset than
it can be
ds.tables("thet able").rows(the rownumber)("the Item") = "xxxx"

I hope this helps?

Cor

"Rudy" <Ru**@discussio ns.microsoft.co m>
> Hi all,
> I know this is easy, just can't seem to get it. I have a windows form,
> and
> a text box, with a value already in it. I need to add that value to a
> table.
> It's just one value, so the entire row doesn't get filled. I have a
> connection and all that stuff.
>
> Private Sub btnPlaceBet_Cli ck(ByVal sender As System.Object, ByVal e As
> System.EventArg s) Handles btnPlaceBet.Cli ck
> ' Dim Myds As Footbet.DStable
> ' txbxCPwage.Data Bindings.Add("t xbxCPwage", Myds, "TableID.Pa ss")
>
> Just looking for the code to pass this value to the DS.
>
> TIA!
> Rudy
>

Nov 21 '05 #5
Hi DuPont,
I am getting the following error - Object reference not set to an instance
of an object
This gets stopped at the objSqlRow = objSqlDs.tables (0).NewRow

I wrote the code out like you suggested, i didn't use...
objSqlDa = New SqlDataAdapter( "strSqlTxt" , objSqlConn)
objSqlCmdB = New SqlCommandBuild er(objSqlDa)
objSqlDa.Fill(o bjSqlDs) Then I did try it, but got a Null Value error.

I don't understand why I need a SELECT statement, when I'm doing an update.
I guess I'm a little confused.

Thanks for your patcience!

Rudy

"DuPont" wrote:
Hello Rudy,

Your right this is actually easy but a little bit of code writing will be
involved.

First, Are you writing these values to existing records or are you creating
a new record based on these formulas.. Its not a big deal if which one your
doing or if your doing both..

You will need the following

SqlConnection
SqlDataAdapter
SqlCommandBuild er
DataSet
DataRow

Exp..

Dim objSqlConn As SqlConnection
Dim objSqlDa As SqlDataAdapter
Dim objSqlCmdB As SqlCommandBuild er
Dim objSqlDs as New DataSet
Dim objSqlRow as DataRow

objSqlConn = New SqlConnection(S tring of connection)
objSqlConn.Open

Dim strSqlTxt As String = ("Your query statement, usually a SELECT type")
**** Now this can be written in a manner as to return existing records or
where a field = Null so you nothing is returned, but you have a base for
adding new records.****

objSqlDa = New SqlDataAdapter( "strSqlTxt" , objSqlConn)
objSqlCmdB = New SqlCommandBuild er(objSqlDa)
objSqlDa.Fill(o bjSqlDs)

*** This next bit of code is for adding a record and filling the values ****

objSqlRow = objSqlDs.Tables (0).NewRow

With objSqlRow
.Item("TextBox1 ") = TextBox1.Text
.Item("TextBox2 ") = TextBox2.Text
Ect ect ect

End with

objSqlDs.Tables (0).Rows.Add(ob jSqlRow)
objSqlDa.Update (objSqlDs)

****Now if you have a query that is searching for an existing record you can
do the samw but with out adding a new record ****
objSqlRow = objSqlDs.Tables (0).Rows(0)

With objSqlRow

.Item("TextBox1 ") = TextBox1.Text
Ect, ect,ect ect..

End With

objSqlDa.Update (objSqlDs)

Well you might get the idea, if you have any questions feel free to ask...

Best regards,


"Rudy" wrote:
Hi Cor,
Thank you for your input. Let me try to explain a little bit better. I have
an answer to a formula that will show up in textbox1. I have 4 textboxs with
the same situation, except the formula is diffrent for each textbox,
therefore, four diffrent answers. In my table i have a column name textbox1,
2, 3, and 4, to match the information to the form. Anyone of the values in
the textbox need to be placed in the table, just 1 or 2 or 3 or all 4 at any
time. When the ENTER button click_event is fired, it needs to take the
values, put them in the approiate coulmns. I'm using SQL by the way for
this. So I'm not sure if I can specify which row it will go into, because it
really doesn't matter. the info will just keep adding to the next row. I
guess the row number would relate to how many times the ENTER click event is
fired. first click, row 1, second click, row 2. In addition, to make things
more interesting, I need to be able to have 5 client computers that has this
setup, going to one SQL server. The number of clicks would actually be total
number from all five clients. Right now I have column in the table to keep
track of which client is enter the values. But I thought about just make
duplicate tables, for the diffrent clients, not sure which would be better.
The max clients I may have is 100. I hope this make sense. Sorry for
rambling on.
Rudy
"Cor Ligthert" wrote:
Rudy,

I do not understand you, therefore I give you 2 answers, if you want to add
it to the databaset table, than you have to create an SQL insert command and
than use an SQLcommand.nonq uery to update your database, that is all.

http://msdn.microsoft.com/library/de...QueryTopic.asp

When you want to add it to an item in a row in a datatable in a dataset than
it can be
ds.tables("thet able").rows(the rownumber)("the Item") = "xxxx"

I hope this helps?

Cor

"Rudy" <Ru**@discussio ns.microsoft.co m>
> Hi all,
> I know this is easy, just can't seem to get it. I have a windows form,
> and
> a text box, with a value already in it. I need to add that value to a
> table.
> It's just one value, so the entire row doesn't get filled. I have a
> connection and all that stuff.
>
> Private Sub btnPlaceBet_Cli ck(ByVal sender As System.Object, ByVal e As
> System.EventArg s) Handles btnPlaceBet.Cli ck
> ' Dim Myds As Footbet.DStable
> ' txbxCPwage.Data Bindings.Add("t xbxCPwage", Myds, "TableID.Pa ss")
>
> Just looking for the code to pass this value to the DS.
>
> TIA!
> Rudy
>

Nov 21 '05 #6
Rudy,

A fill is not an update, that is reading the data into the datast
A update is an update.

\\\something like this is a complete reading and updating,
\\\however there is needed a lot of checking etc with this.
\\\and therefore this is almost the most simple format.
dim ds as new datataset
dim SQLtxt as string = Select * from mytable"
Da = New SqlDataAdapter( "SqlTxt", Conn)
Da.Fill(Ds)
Cmd = New SqlCommandBuild er(Da)
ds.tables(0).ro ws(0).item(1)=" SeconditemFirst rowChangedFromT extbox"
da.update(ds)
///

I hope that this helps?

Cor
Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
349
by: Ari A | last post by:
I have created two forms in VisualBasic.net. When the user hit a button on the FormB must a message box open showing data from a textbox on FormA. Both forms are open at same time. I have done this by using global variant but how can I do it by writing a line of code in FormB? Thanks Ari.
1
4697
by: Shayer | last post by:
Hello I want to add some dynamic control in the win form when i press a button I write the following line of code. But the problem is instead of displaying 10 textbox it display 9 textboxes.But it display another textbox when i hit the button again. Can any one pls give me any solution of it. Anyother alternative solution is appriciable as well. Thanks
5
1789
by: Taryon | last post by:
Consider the Form A calling the Form B. In the Form B i need to access the values of the Form A textbox. Normally i create the textbox as public. BUT in this case, the textbox of Form A will be created on the fly and i cant use the MODIFIERS. Anyone has an idea how to do it?
3
4879
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
4
2497
by: Bas Groeneveld | last post by:
I am developing an ASP.NET application part of which consists of a data entry wizard defined by entries in a data table - ie the controls on each page of the wizard are determined by definitions in the table. I know that I can dynamically add controls (eg a textbox) to the page controls collection of a web form in a server event which will then be rendered onto the form, as in the following snippet: System.Web.UI.WebControls.TextBox...
0
2399
by: Luis Esteban Valencia | last post by:
Hello I wrote a program with code behind in C# to add row into table dynamically and the program worked very well in .Net Framework 1.1. When I run this program in .Net Framework 2.0 beta version, the program is not working as in version 1.1. So what is the problem? Microsoft declared that the version 2.0 is fully backward support, but it is not. Is that the problem with 2.0 version? I find out the problem in version 2.0. After...
0
3004
by: pd123 | last post by:
I'm new to C# and .net and I'm trying to create a form that will register users in a sql server database. I have the following code but when I run the code I get an error " The name 'Peter' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted. Where Peter is the value entered in the textbox for firstname (fnameTBox) I'm sure the problem is something obvious but I...
2
1624
by: Tom | last post by:
I have a textbox on my web form were users can enter in 1 name or many names. The form then validates the name against the database. If the name is valid its then saved into a varaible to be used at a later time. The issue I'm having is as follows: the user enters in 2 names John, Greg clicks my valid button they're both valid so both names are stored in the variable so my variable looks like John,Greg and both are in the textbox. ...
2
7858
by: Hitman | last post by:
Hi Everyone, I have a little bit of problem with my database. I have a textbox ( the name of the textbox is location) on one form and 1 command button. I also made another form with 1 textbox (the name of the textbox is designator) . I want to use vb on programming the command button. All I want to happen is that after I place some text on the texbox (location) I click the command button and the text on (location) will be copied to the other...
0
8888
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9176
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8097
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.