We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,494 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

how to make search in sql database in asp.net using C#?

hi i have a table like this for attendence:

table name attendence.
id  
std_rolNum  
std_fname  
date  
std_bkfast  
std_lunch  
std_dinner

i want to make search on the base of date, std_rolnum, std_lunch, std_bkfast and std_dinner.

so that if on the same date if student have already taken breakfast, lunch or dinner he couldn't mark attendence.
so i have to select multiple columns like date and roll_number.
but i couldn't implement my logic in to c#....

2
Contributors
2
Replies
3 Hours
Discussion Span
5 Months Ago
Last Updated
4
Views
Question
Answered
shahai.ali
Light Poster
48 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Did you already produce the SQL Query? What problem did you have in your c# logic?

JorgeM
Industrious Poster
4,024 posts since Dec 2011
Reputation Points: 297
Solved Threads: 549
Skill Endorsements: 115

thenx JorgeM for your reply. actually i have the following in c#:

SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=c:\users\shahaiali\documents\visual studio 2010\Projects\apps\Database1.mdf;Integrated Security=True;User Instance=True");

            string sql = @"select * from myTable where id = 3 ";
            string str;
            conn.Open();
                SqlDataAdapter da = new SqlDataAdapter(sql, conn);
                DataSet ds = new DataSet();

                da.Fill(ds, "myTable");
                DataTable dt = ds.Tables["myTable"];

                    foreach (DataRow row in dt.Rows)
                    {
                        str = Convert.ToString(row["fName"]);
                        if (str == "")
                        {
                            Console.WriteLine("invalid");
                        }
                        else
                        {
                            Console.WriteLine(str);
                        }

in my above scnario the condition is true mean there is no entry against the id 3. as the condition is true it couldn't enter to the block for empty value.

shahai.ali
Light Poster
48 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 5 Months Ago by JorgeM

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0563 seconds using 2.66MB