none
Searching the Database RRS feed

  • Question

  • Hi!
    How can I look trough all of one of my database table’s columns and find one table? I mean for example I have a table named ‘table1’ and each table has 4 columns ‘table id’ as the primary key, ‘first name’, ‘last name’ and ‘group’. I want to find the primary key value of the table which the last name is ‘smith’. How can I do that?
    And after that, (this table has relationship with another which named ‘table2’ and that table has 2 columns primary key and ‘group name’) how can I find the group name by the primary key of table1?
    Thank you!
    Tuesday, September 11, 2007 11:49 AM

All replies

  • This depends, do you want to pull all the data form the database into a dataset.  You can use the abilities of the dataset to perform the queries you are requesting.

    You could just build your queries into the database to filter the information you require.  That seems a bit simpler rather than pulling all the data to a dataset then sorting through it.
    Tuesday, September 11, 2007 1:10 PM
  •  RichardSny wrote:
    This depends, do you want to pull all the data form the database into a dataset.  You can use the abilities of the dataset to perform the queries you are requesting.

    You could just build your queries into the database to filter the information you require.  That seems a bit simpler rather than pulling all the data to a dataset then sorting through it.

    I got nothing! Please tell me more.

    +++
    e.g. i have a table which has a timedate column and i want to find the primary key of one which has the least value for timedate. How can i do that?

    Tuesday, September 11, 2007 5:12 PM
  • Just make a query that queries the table for all the timedate and primary key colums.  put them in desc order and only pull back the 1st column.  That will be what you are looking for.

    http://www.java2s.com/Code/CSharp/Database-ADO.net/Select-Query.htm

    The website above shows a good example on how to use ADO.Net to access the dbs.  Again, your query should do all the work you are asking about, you just need to read the 1st row.
    Tuesday, September 11, 2007 5:23 PM
  •  RichardSny wrote:
    Just make a query that queries the table for all the timedate and primary key colums.  put them in desc order and only pull back the 1st column.  That will be what you are looking for.

    http://www.java2s.com/Code/CSharp/Database-ADO.net/Select-Query.htm

    The website above shows a good example on how to use ADO.Net to access the dbs.  Again, your query should do all the work you are asking about, you just need to read the 1st row.

    Thank you for your help, but this site doesn’t work! (IE says: “This program cannot display the webpage”)

    Tuesday, September 11, 2007 6:42 PM
  • Try Here

    Ok, try above.  I am sorry for being so sketchy on the explination and the fact that there are no code snibits.  Been busy today, but CodeSource is a great site and will give you a good explination on how to use ADO.Net
    Tuesday, September 11, 2007 6:49 PM
  •  RichardSny wrote:
    Try Here

    Ok, try above.  I am sorry for being so sketchy on the explination and the fact that there are no code snibits.  Been busy today, but CodeSource is a great site and will give you a good explination on how to use ADO.Net

    Again thank you for your answer. I don’t think so. I think just ADO.Net was my answer and you told me that. (I was programming in dos at school and I used it for writing logical programs (like in IOI). So I don’t know so much on windows programming. I read something on ADO.Net after your used it in your answer and now I think that it was the best answer!) But please give me some code samples here. Thank you again for your help.


    Tuesday, September 11, 2007 7:01 PM
  • Please tell me how can i use ADO.Net or at least give me some sources for biginners(not somthing like MSDN library). Thank you.
    Saturday, September 15, 2007 12:40 AM
  • Here are some websites I found by googleing "ADO.Net +C# +Beginners" or even "ADO.Net +C#"

    http://www.csharphelp.com/archives3/archive586.html

    http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson01.aspx


    The basic concept of ado.net is that you create a data connection between your code and your db.  That connection includes all of the necessary information to access/query the database.  Once you have queried the appropriate information is returned to you in one or multiplet tables.  This is stored in an object type called a DataSet,Click on DataSet to learn more.  Then once stored in the dataset you can use an iteratory to go through and access the information your require.  Again google around or use the links I sent you.  They give a much more detailed explination on what ADO.Net is and how to use it.
    Monday, September 17, 2007 12:45 PM