1.11M Members

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

 
0
 

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#....

 
0
 

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

 
0
 

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.

Question Answered as of 1 Year Ago by JorgeM
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: