Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. SQL/C#

SQL/C#

Scheduled Pinned Locked Moved C#
helpcsharpdatabase
5 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Harry2000
    wrote on last edited by
    #1

    Hi I have used this for the slq statem SELCT FirtName, LastName, ID,From Coustomer WHERE FirstName LIKE '[A-Z]' C# private void button1_Click(object sender, System.EventArgs e) { oleDbConnection1.Open(); oleDbDataAdapter2.SelectCommand.Parameters["LastName"].Value = textBox1.Text; dataSet11.Clear(); oleDbDataAdapter2.Fill(dataSet11) oleDbConnection1.Close(); } But when I run it gave a and error can u help me anyone Harrison Brock

    M M 2 Replies Last reply
    0
    • H Harry2000

      Hi I have used this for the slq statem SELCT FirtName, LastName, ID,From Coustomer WHERE FirstName LIKE '[A-Z]' C# private void button1_Click(object sender, System.EventArgs e) { oleDbConnection1.Open(); oleDbDataAdapter2.SelectCommand.Parameters["LastName"].Value = textBox1.Text; dataSet11.Clear(); oleDbDataAdapter2.Fill(dataSet11) oleDbConnection1.Close(); } But when I run it gave a and error can u help me anyone Harrison Brock

      M Offline
      M Offline
      mistery22
      wrote on last edited by
      #2

      SELCT FirtName, LastName, ID,From Coustomer WHERE FirstName LIKE '[A-Z]' SELECT FirstName, LastName, ID FROM Customer WHERE FirstName LIKE ??? ??? = I don't see what you want to do here. This is sure no SQL the like operater only allows to use wildcards % and _. assume next records in DB: cat C# dog bat faster LIKE 'c%' returns cat and C# LIKE 'c_' returns C# LIKE '_a_' returns cat and bat LIKE '_a%' returns cat, bat and faster % for a range of caracters _ for just 1 character Let know what you want and I'll help you with the statement :) Try this class named mySQL_Data with method get dataSet. (example with mysql) public mySQL_Data(string userName, string database, string password, string host) { // constructor logic this.userName = userName; this.database = database; this.password = password; this.host = host; conString = "DRIVER={MySQL ODBC 3.51 Driver};" + //place here the driver name like you "SERVER="+host+";" + //find in Windows ODBC description "DATABASE="+database+";" + "UID="+userName+";" + "PASSWORD="+password+";" + "OPTION=3"; } public override DataSet getDataSet(string query, string table) { OdbcConnection conn = new OdbcConnection(conString); DataSet ds = new DataSet("name"); try { conn.Open(); OdbcDataAdapter da = new OdbcDataAdapter (query, conn); da.Fill(ds, table); conn.Close(); } catch(OdbcException odbcError) { MessageBox.Show( "Native: " + odbcError.Errors[0].NativeError.ToString() + "\n" + "SQLState: " + odbcError.Errors[0].SQLState.ToString() + "\n" + "Message: " + odbcError.Errors[0].Message,"ODBC Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return ds; } greetz

      1 Reply Last reply
      0
      • H Harry2000

        Hi I have used this for the slq statem SELCT FirtName, LastName, ID,From Coustomer WHERE FirstName LIKE '[A-Z]' C# private void button1_Click(object sender, System.EventArgs e) { oleDbConnection1.Open(); oleDbDataAdapter2.SelectCommand.Parameters["LastName"].Value = textBox1.Text; dataSet11.Clear(); oleDbDataAdapter2.Fill(dataSet11) oleDbConnection1.Close(); } But when I run it gave a and error can u help me anyone Harrison Brock

        M Offline
        M Offline
        Mike Ellison
        wrote on last edited by
        #3

        I'm guessing the problem is in your select statement (I don't think LIKE '[A-Z]' can work). Can you post the specific error message?

        H 1 Reply Last reply
        0
        • M Mike Ellison

          I'm guessing the problem is in your select statement (I don't think LIKE '[A-Z]' can work). Can you post the specific error message?

          H Offline
          H Offline
          Harry2000
          wrote on last edited by
          #4

          I have a textbox that I want to enter a value in. Than search the database for the closes matches. Harrison Brock

          M 1 Reply Last reply
          0
          • H Harry2000

            I have a textbox that I want to enter a value in. Than search the database for the closes matches. Harrison Brock

            M Offline
            M Offline
            mistery22
            wrote on last edited by
            #5

            Ok I think you want something like The user enters 'Arn' and sql gives Arnold then your like statemint will be Like 'Arn%' or "... LIKE '" + TextBox1.Text + "%';"; Greetz

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups