Getting Server Error "Syntax error converting the nvarchar value 'Sonoma' to a column of data type int."

Hi, all

I'm getting this error at runtime when my page tries to populate a datagrid. Here's the relevant code.

First, the user selects his choice from a dropdownlist, populated with a sqldatasource control on the aspx side:

<asp:SqlDataSource ID="sqlDataSourceCompany" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                SelectCommand="SELECT [PayrollCompanyID], [DisplayName] FROM [rsrc_PayrollCompany] ORDER BY [DisplayName]">
            </asp:SqlDataSource>

 And the dropdown list's code:

<asp:DropDownList ID="ddlPayrollCompany" runat="server" AutoPostBack="True" DataSourceID="sqlDataSourcePayrollCompany"
                DataTextField="DisplayName" DataValueField="PayrollCompanyID">
            </asp:DropDownList>

Then, I use the selectedindexchanged event to bind the data to the datagrid. Here's that code:

 

1    Sub BindData()
2    
3    		Dim ds As New DataSet
4    		Dim sda As SqlClient.SqlDataAdapter
5    		Dim strSQL As String
6    		Dim strCon As String
7    
8    		strSQL = "SELECT [SocialSecurityNumber], [Prefix], [FirstName], [LastName], [HireDate], [PayrollCostPercent], " & _
9    		 "[Phone], [BadgeNumber], [IsSupervisor], [SupervisorID], [IsUser], [IsScout] FROM [rsrc_Personnel] " & _
10   		 "WHERE ([PayrollCompanyID] = @PayrollCompanyID)"
11   
12   		strCon = "Data Source=DATASOURCE;Initial Catalog=DATABASE;User ID=USERID;Password=PASSWORD"
13   
14   		sda = New SqlClient.SqlDataAdapter(strSQL, strCon)
15   
16   		sda.SelectCommand.Parameters.Add(New SqlClient.SqlParameter("@PayrollCompanyID", Me.ddlPayrollCompany.SelectedItem.ToString()))
17   
18   		sda.Fill(ds, "rsrc_Personnel")
19   
20   		dgPersonnel.DataSource = ds.Tables("rsrc_Personnel")
21   		dgPersonnel.DataBind()
22   
23   	End Sub
24   

 

I'm assuming my problem lies in line 16 of the above code. I've tried SelectedItemIndex, SelectedItemValue too and get errors for those, as well.

What am I missing?

Thanks for anyone's help!

Cappela07


"f u cn rd ths, u cn gt a gd jb n cmptr prgmmng." - Anon
0
capella07
4/20/2007 3:13:36 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

2 Replies
847 Views

Similar Articles

[PageSpeed] 59

Looks like the PayrollcompanyId is an INT type. you need to do an explicit Convert.ToInt16 or Convert.ToInt32(ddlPayrollCompany.SelectedItem.Text) or ddlPayrollCompany.SelectedItem.Value whichever has the value for PayrollcompanyId.
***********************
Dinakar Nethi
Life is short. Enjoy it.
***********************
0
ndinakar
4/20/2007 5:02:01 PM

I need to take a break from this project! Major brain fart - I THOUGHT I tried " 

("@PayrollCompanyID", Me.ddlPayrollCompany.SelectedValue)"

 But something told me to try it again, AFTER having posted here, and it worked fine.

I HATE when that happens!

But thanks, anyway, ndinakar.

Capella07


"f u cn rd ths, u cn gt a gd jb n cmptr prgmmng." - Anon
0
capella07
4/20/2007 5:06:22 PM
Reply:

Similar Artilces:

Syntax error converting the nvarchar value 'no data' to a column of data type int
Hi all Here is an error I'm getting that I hope you can help with. Exception Details: System.Data.SqlClient.SqlException: Syntax error converting the nvarchar value 'no data' to a column of data type int. basically I'm trying to update a record using the Insert template in FormVeiw. The problem field is related to a  dropdownlist field that works as follows <asp:Label ID="LabelSchemeArea" runat="server" Visible="False" /> 'labelSchemeArea contains a value such as 1 or 2 or 3 <td style="width: 209px">Scheme...

Problem with "converting the nvarchar value 'xxxxxID' to a column of data type int".
Hi, I have a webform with a drop-down listbox, binded to a table and a GridView, binded to another table. My goal is when I select a value (country in my case) in the drop-down listbox to change what is shown in the GridView, based on the ID that I get from the drop-down listbox. Here is the code (the important parts...): Select a Country : <asp:DropDownList ID="CountriesDropDownList" runat="server" DataSourceID="SqlDataSource2" DataTextField="Name" DataValueField="CountryID" Width="220px" AutoPostBack="True"> </asp:DropDownList> <asp:SqlDataSource ID="SqlDataSource2...

Syntax error converting the nvarchar value '*' to a column of data type int.
This error is pointing to the dashed line, but where is this trying to convert this into an integer. the only one of these fields that have a "*" is the account name. Dim Cmd as SQLCommand Cmd = New SQLCommand( "SELECT DISTINCT dbo.AccountsInfo.AccountID, dbo.AccountsToMove.Move, dbo.AccountsInfo.AccountName, dbo.AccountsInfo.City, dbo.AccountsInfo.State, dbo.AccountsToMove.TerritoryID, dbo.AccountsToMove.SalesLastYear FROM dbo.AccountsToMove INNER JOIN dbo.AccountsInfo ON dbo.AccountsToMove.AccountID = dbo.AccountsInfo.AccountID Where dbo.Accountstomove.TerritoryID = ...

Update a Tablefield with Concatenating 4 fields
Hi,Within the vb-script from an ASP.NET webpage i'm trying to update an sqltable. I want to update a particular tablefield. Using the String as below:The field docpad (important to now) is a VARCHAR field with length 250. After executing the code i become an error: Syntax error converting the varchar value '~/Uploadmap/' to a column of data type int.I do not understaend this error because the targetfield is type VARCHAR and not int.   This is the code i'm using. What is it what i'm doing wrong?  sql2.Append("UPDATE dbo.T_20001_Documenten SET docpad = &...

Syntax error converting the varchar value 'MatterID.Value' to a column of data type int.
I'm getting this error when I pass a value via querystring into a second page and try to use that value in my sql select statement. ... just passing a value and trying to use it to select.  In the db, MatterID is an int.  How do I pass it as an int instead of a varchar?  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadMatterID.Value = Request.QueryString("MatterID")End Sub Protected Sub CalculateRunningTotal()Dim conn As SqlConnectionDim comm As SqlCommandDim reader As SqlDataReaderDim connectionString As...

System.Data.SqlClient.SqlException: Syntax error converting the varchar value 'V' to a column of data type int
 I am using  a stored procedure which returns a value of charecter datatype 'V' to the calling program.I am getting an sql exception System.Data.SqlClient.SqlException: Syntax error converting the varchar value 'V' to a column of data type inti didnot define any int datatype in my tablethis is my codeSqlCommand com = new SqlCommand("StoredProcedure4", connection);com.CommandType = CommandType.StoredProcedure;  SqlParameter p1 = com.Parameters.Add("@uname", SqlDbType.NVarChar);SqlParameter p2 = com.Parameters.Add("@op...

Syntax error converting the varchar value 'email' to a column of data type int.
Well I am doing a simple insert through a stored procedure..., but I am getting this error. In my table I have the UserID as a VARCHAR 100. I am storing from a textbox that will have number because its there email. But I am not converting anything. Do I need to convert in this scenario??  Server Error in '/pickem' Application. Syntax error converting the varchar value 'johndoe@hotmail.com' to a column of data type int. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more informati...

Exception {"Conversion failed when converting the nvarchar value 'Chuck Designs' to data type int."}
I have the below methods. They generate the error above at the sqlreader.read(); line. Please help.  All I want is a simple true false check to see if a value is already in the db.public static void InsertVendor(string vendor) {if (!CheckVendorValue(vendor) == true) {using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["VendorEvaluationConnectionString"].ConnectionString)) { conn.Open();SqlCommand cmd = new SqlCommand("Insert into tblVendors values (@vendor_name)", conn); cmd.Parameters.AddWithValue("@vendor_name", ve...

How come i get a error message "Incorrect syntax near 'nvarchar'" when i try to edit the data?
 Hi, I'm trying to edit/update the gridview but whenever i tried to update/edit the data, there will be error message saying that "Incorrect syntax near 'nvarchar'". What is the likely cause of that error message? Thanks Server Error in '/WSD Project - Cam-Mart' Application. Incorrect syntax near 'nvarchar'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax ne...

Syntax error converting the varchar value 'Select Office' to a column of data type int.
I have a web page which contains a dropdownlist that is populated from a stored procedure. After I bind the dropdown to the datasource I want to insert an item using the code as follows: ddlFO.Items.Insert(0, "Select Office") No error is reported during the page load event; however, when I load the page in the browser it receive the subject error message. I use the same stored procedure and insert command on several other pages within this application without causing an exception. The full code of the sub follows: Public Sub bindFO(ByVal sender As System.Object, ByVal e As System.Event...

.NET Error Message "Server Error in '/' Application."
I continue to get this error message randomly for several .NET applications and I'm trying to determine if this issue is "Permissions" or "Application Configuration" related.  What are the necessary NTFS security groups and rights that should be applied to the file directories?  Or what is the resolution to resolving this complex problem? HELP! moblack29   The first step is posting the full error message. JeffPlease: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue....

Trying to transfer a Web Service made in .NET aspx on my "localhost", to online and getting BC30002: Type 'localhost.Convert' is not defined. error
I think I get the general idea of this error.  The webservice works on my computer as Visual Web Developer somehow makes a temporary server out of my computer.  But when I try to FTP my full ASP page I get an error that localhost is not defined.  This makes sense as I am sure the web server for GoDaddy is not called localhost for me.  Now in my App_WebReferences folder in my program I have a local host folder that holds 3 automatically generated files which are somehow "calls" to a webservice that I built.  So I have the original files for the webservi...

Trying to load user control Dynamcially but getting error " Control 'ctl02_GridView1' of type 'GridView' must be placed inside a form tag with runat=server"
I am tired of this error and now writing a post.  My Web application has two pages. Page one has drop down list which redirect the page to another page . where I am going to load the usercontrol dynamically according to the choice of the user.     protected void ddlViewReport_SelectedIndexChanged(object sender, EventArgs e)  { if (ddlViewReport.SelectedIndex == 1) { Session["ReportType"] = ddlViewReport.SelectedIndex; Response.Redirect("RepReportingPage.aspx"); int crosspagevalue = ddlViewReport.SelectedIndex; } if (ddlViewReport.SelectedIndex == 2) {...

How do I get around this error "Unable to cast object of type 'System.DBNull' to type 'System.String' "
I am using Visual Developer 2008 Express Edition for the first time, and I keep getting the following error below. The site allows anyone to enter with a valid username and password, but even when I logoff the site I get the same error....like the memory or database is not getting refreshed. I would think that when I initially compile the site that anything left in memory would be flushed out. Can someone please help me to figure this out. Thanks,Ramell P.S. The site is programmed using C#    Unable to cast object of type 'System.DBNull' to type 'System.String&...

Web resources about - Getting Server Error "Syntax error converting the nvarchar value 'Sonoma' to a column of data type int." - asp.net.sql-datasource

Resources last updated: 12/23/2015 12:09:35 AM