473,395 Members | 1,343 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.

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 1843
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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...

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.