Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6750943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:52:05+00:00 2026-05-26T12:52:05+00:00

I’ll try to clarify by using the following example. In here I have two

  • 0

I’ll try to clarify by using the following example. In here I have two Drop down lists (ddlInsertEmployee + ddlInsertCustomer) which should both be bound to fetch data from tables [Employee.EmployeeID] and [Customer.CustomerID] and insert it into table [Task].

The problem is that it inserts data from Employee.Fullname and Customer.Fullname into resp. Employee.EmployeeID and Customer.CustomerID. If I would change the Drop down lists to textboxes, and manually insert the IDs, it works like a charm, but this is not very efficient, I want to be able to see the entire Fullname.

I don’t know how to change my Sqlstring in order to make this work correctly. I hope this makes any sense. Any help much appreciated!

Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.DropDownList


   Protected Sub btnSubmit_Click(sender As Object, e As System.EventArgs) Handles btnSubmit.Click
        Dim MyConn As OleDbConnection
        Dim cmd As OleDbCommand
        Dim Sqlstring, TaskDesc, TaskSolved, Employee, Customer, DateIn, DateOut, TaskHours As String

        TaskDesc = txtTaskDesc.Text
        TaskSolved = txtTaskSolved.Text
        Employee = ddlInsertEmployee.Text
        Customer = ddlInsertCustomer.Text
        DateIn = txtDateReg.Text
        DateOut = txtDateSolved.Text
        TaskHours = txtHours.Text

        MyConn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\DATABASE.accdb;")

        MyConn.Open()
        Sqlstring = "INSERT INTO Task (TaskDesc, TaskSolved, EmployeeID, CustomerID, DateIn, DateOut, TaskHours) VALUES ('" + TaskDesc + "', '" + TaskSolved + "', '" + Employee + "', '" + Customer + "', '" + DateIn + "', '" + DateOut + "', '" + TaskHours + "')"
        cmd = New OleDbCommand(Sqlstring, MyConn)
        cmd.ExecuteNonQuery()
        MyConn.Close()
        lblMessage.Text = "Task Added Successfully !!!"
    End Sub

End Class


--------

 Employee 
    <asp:DropDownList ID="ddlInsertEmployee" runat="server" AutoPostBack="True" 
        DataSourceID="SqlDataSource5" DataTextField="EmployeeFullName" 
        DataValueField="EmployeeFullName">
    </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSource5" runat="server" 
        ConnectionString="<%$ ConnectionStrings:conntoDB %>" 
        ProviderName="<%$ ConnectionStrings:conntoDB.ProviderName %>" 
        SelectCommand="SELECT EmployeeFullName, EmployeeID FROM Employee">
    </asp:SqlDataSource>
    &nbsp;&nbsp;&nbsp;
    <br />
    <br />
    Customer&nbsp;<asp:DropDownList ID="ddlInsertCustomer" runat="server" 
        AutoPostBack="True" DataSourceID="SqlDataSource6" 
        DataTextField="CustomerFullName" DataValueField="CustomerFullName">
    </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSource6" runat="server" 
        ConnectionString="<%$ ConnectionStrings:conntoDB %>" 
        ProviderName="<%$ ConnectionStrings:conntoDB.ProviderName %>" 
        SelectCommand="SELECT CustomerID, CustomerFullName FROM Customer">
    </asp:SqlDataSource>

I receive the error:

Exception Details: System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.

Source Error:

Line 60:         Sqlstring = "INSERT INTO Task (TaskDesc, TaskSolved, EmployeeID, CustomerID, DateIn, DateOut, TaskHours) VALUES ('" + TaskDesc + "', '" + TaskSolved + "', '" + Employee + "', '" + Customer + "', '" + DateIn + "', '" + DateOut + "', '" + TaskHours + "')"
Line 61:         cmd = New OleDbCommand(Sqlstring, MyConn)
[B]Line 62:         cmd.ExecuteNonQuery() Line 63:         MyConn.Close()[/B]
Line 64:         lblMessage.Text = "Task Added Successfully !!!"


Source File: C:\Projekt\NewTask.aspx.vb    Line: 62
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:52:06+00:00Added an answer on May 26, 2026 at 12:52 pm

    Try setting the DataValueField of your ddlInsertCustomer to CustomerID (and similar for your employee dropdown). Then you can use the ddl.SelectedValue property to save to the database, but a user would still see the name property.

    Also plugging text in a textbox into your SQL queries is a really bad idea as it opens you up to SQL injection. Using SQL parameters is a really good idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.