Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello folks..

I am learning .net these days and have a question need a bit help here..

How to achieve this:

I am designing my form here as simple as i can explain you..:

FORM:

Search Name: (User can enter 1 or many names here to search in database seperated by commas)
 -------------------
|                   |      SUBMIT
|                   |
 -------------------

Output Result: (Once user submit the query it will lookup those entered name 1 or many in the 3 different tables for its existance.. If they exist or not then the output will be shown as below..)

Name   |   Class X    |   Class XI   |   Class XII
--------------------------------------------------
First  |    Yes       |    NO        |    NO
Second |    YES       |    YES       |    YES
.
.
.
.
N entry|   ......     |    .....     |   ......




This should be the way the output for N search should display, Now i am stuck how to do that.. I am not that familiar with .net please help with a code explanation or somewhere where i can have this goal achieved. I hope anyone can help me.. Sorry for such easy question.

Please provide me a sample for this function. . :(
Posted
Comments
_Asif_ 8-Jul-13 6:13am    
Please share the tables details

Hello,

You can use GridView web form control to display multiple records. Please refer to following tutorials, those should get you started.


Since you need to check for existance of the record in three different tables you can do soby Fire three different count SQL's using SQLCommand and based on the output (which will be a count of matching records found) you can proceed further to display the result. The code for a single query will be something like shown below.
C#
Int32 intCnt1 = 0;
string sql = "SELECT COUNT(1) FROM your_table WHERE search_col  = @searchTerm";
using (SqlConnection conn = new SqlConnection(connString)) {
    SqlCommand cmd = new SqlCommand(sql, conn);
    cmd.Parameters.Add("@searchTerm", SqlDbType.VarChar);
    cmd.Parameters["@searchTerm"].Value = your_value;
    try {
        conn.open();
        intCnt1 = (Int32) cmd.ExecuteScalar();
    }
    catch (Exception ex) {
        // Code to handle exception
    }
}

Regards,
 
Share this answer
 
v2
Comments
Devil9919 8-Jul-13 3:52am    
@Prasad, Buddy i am not trying to display data from database but i am trying to confirm data from database and display that data exist in those tables or not .

please help me that way.

and regarding the Solution 1, buddy i have tried that but can't get any help what i need.

please anyone can help me... Can anyone provide me code that atleast checks 1 record not for multiple ones.

waiting for help ! Cheers ! :)
Devil9919 8-Jul-13 7:17am    
PLease help me ! come one friends help me too.. :(
try this

http://stackoverflow.com/questions/15976366/trying-to-pass-an-array-of-values-to-search-using-in[^]


or


http://www.williamrobertson.net/documents/comma-separated.html
 
Share this answer
 
try this
VB
Dim Arr As String()
        Dim con As OleDbConnection
        Dim cmd As OleDbCommand
        Dim str As String
        Dim dr As OleDbDataReader
        Arr = TextBox1.Text.Split(",")
        For Each name As String In Arr
            con = New OleDbConnection("YourConnectionString")
            con.open()
            str = "select * from YourTableName where YourColumnName like '%" & name & "%'" ''First Table To Search
            cmd = New OleDbCommand(str, con)
            dr = cmd.ExecuteReader
            If dr.HasRows Then
                DataGridView1.Rows.Insert(dr(0), dr(1), dr(2), dr(3)) 'And so on
            End If
            dr.Close()
            str = "select * from YourTableName where YourColumnName like '%" & name & "%'" ''Second Table To Search
            cmd = New OleDbCommand(str, con)
            dr = cmd.ExecuteReader
            If dr.HasRows Then
                DataGridView1.Rows.Insert(dr(0), dr(1), dr(2), dr(3)) 'And so on
            End If
            dr.Close()
        Next
 
Share this answer
 
v2
Comments
Devil9919 8-Jul-13 8:21am    
Thanks for the code, can you explain what is happening after creating connection.
Basmeh Awad 8-Jul-13 8:27am    
as you can see..we are searching for the name in the table which the user have entered in the search box and if we found it we are displaying it in the DataGridView..
Devil9919 8-Jul-13 8:33am    
So exactly this is searching for the name and displaying the name or saying Yes / No kinda ???
Basmeh Awad 8-Jul-13 8:37am    
yes..
Devil9919 8-Jul-13 9:00am    
OK Thanks mate ! I will have a try on this and will let you know ! :) Is this for SQL right ? as i see OLEDB connection stuffs..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900