473,320 Members | 2,083 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.

Filling textboxes with results from a stored procedure

Eva
Hi

I have 2 comboboxes on my form that gathers 2 parameters: The Caravan_Name and the caravan_Length. these 2 values that the user selects are placed into a stored procedure as parameters. The stored procedure is run on the CBoxEditCaravan_Length_SelectedIndexChange
What i want to achieve is to fill the textboxes that are on my form with the results of this query. can someone tell me how i can do this?? I have tried the code below but i keep getting a message that pops up stating ....
cast from string "Length" to type 'integer' is not valid
this message appears everytime i try to change the caravan_length in the combobox

here is my code i tried

'Display the caravan length based on the caravan name selected
Dim Cn As New SqlConnection("data source=PARAGLAPTOP\VSdotNET;initial catalog=CaravanDBLapSQLServ;integrated security=SSPI;persist security info=False;workstation id=PARAGLAPTOP;packet size=4096"

Dim cmdCaraDetails As New SqlCommand("SPSelCaraDetailsOnCaraNameLength", Cn
cmdCaraDetails.CommandType = CommandType.StoredProcedur

'declare the parameter
cmdCaraDetails.Parameters.Add("@CaraName", SqlDbType.Char, 50
cmdCaraDetails.Parameters.Add("@Length", SqlDbType.Char, 10
'now set the value
cmdCaraDetails.Parameters("@CaraName").Value = CBoxEditCaraName.SelectedIte
cmdCaraDetails.Parameters("@Length").Value = CBoxEditCaraLength.SelectedIte

Tr
Cn.Open(
Dim reader5 As SqlDataReade
reader5 = cmdCaraDetails.ExecuteReader(
While reader5.Rea
txtLength.Text = (reader5.GetString("Length")
txtCaraName.Text = (reader5.GetString("Caravan_Model")
txtBeds.Text = (reader5.GetInt16("Beds")
txtPrice.Text = (reader5.GetSqlMoney("Cost")
End Whil
Catch ex As Exceptio
MsgBox(ex.Message
Finall
Cn.Close(
End Tr

the following line (txtPrice.Text = (reader5.GetSqlMoney("Cost"))
in the code above is also highlighted with a message stating...
Value of type 'System.Data.Sqltypes.SqlMoney' cannot be converted to 'String'

can someone plz tell me what i am doing wrong
Can i use the sqldatareader to place single values into a textbox? Im not to sure if this is the right way to go about this??
Nov 22 '05 #1
2 1842
APG
Hi Eva,

Converting the SqlMoney value to string before assigning it to the TextBox
text value will solve the cast error.
ie., txtPrice.Text = reader5.GetSqlMoney("Cost").ToString()

Also check the data type of the "Length" field in the DB. looks like it is
defined as an integer field.

HTH,

APG
"Eva" <an*******@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com...
Hi,

I have 2 comboboxes on my form that gathers 2 parameters: The Caravan_Name and the caravan_Length. these 2 values that the user selects are placed into
a stored procedure as parameters. The stored procedure is run on the
CBoxEditCaravan_Length_SelectedIndexChanged What i want to achieve is to fill the textboxes that are on my form with the results of this query. can someone tell me how i can do this?? I have
tried the code below but i keep getting a message that pops up stating ..... cast from string "Length" to type 'integer' is not valid.
this message appears everytime i try to change the caravan_length in the combobox.
here is my code i tried.

'Display the caravan length based on the caravan name selected.
Dim Cn As New SqlConnection("data source=PARAGLAPTOP\VSdotNET;initial catalog=CaravanDBLapSQLServ;integrated security=SSPI;persist security
info=False;workstation id=PARAGLAPTOP;packet size=4096")
Dim cmdCaraDetails As New SqlCommand("SPSelCaraDetailsOnCaraNameLength", Cn) cmdCaraDetails.CommandType = CommandType.StoredProcedure

'declare the parameters
cmdCaraDetails.Parameters.Add("@CaraName", SqlDbType.Char, 50)
cmdCaraDetails.Parameters.Add("@Length", SqlDbType.Char, 10)
'now set the values
cmdCaraDetails.Parameters("@CaraName").Value = CBoxEditCaraName.SelectedItem cmdCaraDetails.Parameters("@Length").Value = CBoxEditCaraLength.SelectedItem
Try
Cn.Open()
Dim reader5 As SqlDataReader
reader5 = cmdCaraDetails.ExecuteReader()
While reader5.Read
txtLength.Text = (reader5.GetString("Length"))
txtCaraName.Text = (reader5.GetString("Caravan_Model"))
txtBeds.Text = (reader5.GetInt16("Beds"))
txtPrice.Text = (reader5.GetSqlMoney("Cost"))
End While
Catch ex As Exception
MsgBox(ex.Message)
Finally
Cn.Close()
End Try
the following line (txtPrice.Text = (reader5.GetSqlMoney("Cost")))
in the code above is also highlighted with a message stating....
Value of type 'System.Data.Sqltypes.SqlMoney' cannot be converted to 'String'.
can someone plz tell me what i am doing wrong?
Can i use the sqldatareader to place single values into a textbox? Im not

to sure if this is the right way to go about this??
Nov 22 '05 #2
APG
Hi Eva,

Converting the SqlMoney value to string before assigning it to the TextBox
text value will solve the cast error.
ie., txtPrice.Text = reader5.GetSqlMoney("Cost").ToString()

Also check the data type of the "Length" field in the DB. looks like it is
defined as an integer field.

HTH,

APG
"Eva" <an*******@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com...
Hi,

I have 2 comboboxes on my form that gathers 2 parameters: The Caravan_Name and the caravan_Length. these 2 values that the user selects are placed into
a stored procedure as parameters. The stored procedure is run on the
CBoxEditCaravan_Length_SelectedIndexChanged What i want to achieve is to fill the textboxes that are on my form with the results of this query. can someone tell me how i can do this?? I have
tried the code below but i keep getting a message that pops up stating ..... cast from string "Length" to type 'integer' is not valid.
this message appears everytime i try to change the caravan_length in the combobox.
here is my code i tried.

'Display the caravan length based on the caravan name selected.
Dim Cn As New SqlConnection("data source=PARAGLAPTOP\VSdotNET;initial catalog=CaravanDBLapSQLServ;integrated security=SSPI;persist security
info=False;workstation id=PARAGLAPTOP;packet size=4096")
Dim cmdCaraDetails As New SqlCommand("SPSelCaraDetailsOnCaraNameLength", Cn) cmdCaraDetails.CommandType = CommandType.StoredProcedure

'declare the parameters
cmdCaraDetails.Parameters.Add("@CaraName", SqlDbType.Char, 50)
cmdCaraDetails.Parameters.Add("@Length", SqlDbType.Char, 10)
'now set the values
cmdCaraDetails.Parameters("@CaraName").Value = CBoxEditCaraName.SelectedItem cmdCaraDetails.Parameters("@Length").Value = CBoxEditCaraLength.SelectedItem
Try
Cn.Open()
Dim reader5 As SqlDataReader
reader5 = cmdCaraDetails.ExecuteReader()
While reader5.Read
txtLength.Text = (reader5.GetString("Length"))
txtCaraName.Text = (reader5.GetString("Caravan_Model"))
txtBeds.Text = (reader5.GetInt16("Beds"))
txtPrice.Text = (reader5.GetSqlMoney("Cost"))
End While
Catch ex As Exception
MsgBox(ex.Message)
Finally
Cn.Close()
End Try
the following line (txtPrice.Text = (reader5.GetSqlMoney("Cost")))
in the code above is also highlighted with a message stating....
Value of type 'System.Data.Sqltypes.SqlMoney' cannot be converted to 'String'.
can someone plz tell me what i am doing wrong?
Can i use the sqldatareader to place single values into a textbox? Im not

to sure if this is the right way to go about this??
Nov 22 '05 #3

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

Similar topics

1
by: Eva | last post by:
Hi I have 2 comboboxes on my form that gathers 2 parameters: The Caravan_Name and the caravan_Length. these 2 values that the user selects are placed into a stored procedure as parameters. The...
4
by: John | last post by:
Hi everyone, I have a stored procedure which I use to query a table. The first part of the stored procedure uses a cursor to update a temp table whilst the second part of the query actually...
5
by: msprygada | last post by:
I am having a problem with getting a recordset to fill with data in an Access Data Project from a SQL Server database. Here is the code example that is in the Access help files that I can get to...
4
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
2
by: Sandy | last post by:
Hello - I have the following stored procedure and code. I want to put the results in two textboxes. I get to the part where I create the dataset and then I don't know what to do. I tried...
4
by: JC - home | last post by:
Hello.. I've been having some problems for a little while with this which I was sure I would beat...hmmm. Anyway, I have a form with two rich textboxes. One at the top which is to display a...
4
by: jaYPee | last post by:
I have downloaded some source code but I want this to convert the results into datagrid. dr = cmd.ExecuteReader() '**************************************** ' SHOW THE RESULTS...
8
by: stephen.clancy | last post by:
I have created a Table on the fly with embedded textboxes. I need to update a database based on the input to these textboxes. What's the best approach? Sample of setup; Table table = new...
6
by: Uday | last post by:
Hi everyone, I have a ASP page that triggers a db-side stored procedure. At the end of the procedure, it spits out a log file, that this ASP page reads and displays for the users. But the...
0
by: jaeden99 | last post by:
I have a two drop down list box. The first contains district name(district id is the value) and the the second will contain the user name based on the district selected in the first drop down list....
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
1
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...
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: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.