|
-
Jun 3rd, 2005, 03:30 PM
#1
Thread Starter
Hyperactive Member
Datagrid
Hi!
I have to search my database and display the search results in the datagrid.
Its happening fine. I have created a subroutine BindSearchData() and calling it from the Click event of a button. The routine takes the query as an argument. Follwing is the code
Code:
private void BindSearchData(string strSearchSql)
{
OleDbConnection scnnNW = new OleDbConnection(SQL_CONNECTION_STRING);
OleDbCommand scmd = new OleDbCommand(strSearchSql, scnnNW);
OleDbDataAdapter sda = new OleDbDataAdapter(scmd);
DataSet ds = new DataSet();
sda.Fill(ds);
dgCompany.DataSource = ds;
dgCompany.DataBind();
}
My problem is that when no records are found. I have to show it as a message " No Records found." I am coding in c# and a newbie.
Pls help.
-
Jun 4th, 2005, 12:53 AM
#2
Hyperactive Member
Re: Datagrid
not sure though, but you can do this by checking the dataset if fills data on it.
VB Code:
this.dataGrid1.DataSource = ds;
if(ds.Tables.Count>0)
if(ds.Tables[0].Rows.Count>0)
MessageBox.Show("Records found");
else
MessageBox.Show("No records found");
-
Jun 6th, 2005, 03:00 PM
#3
Thread Starter
Hyperactive Member
Re: Datagrid
Thanks! It really helped.
-
Jun 15th, 2005, 06:36 PM
#4
Frenzied Member
Re: Datagrid
i would make your sub return a boolean. that boolean is determined on whether or not the dataset has data. then, when you call that function, you can display a message box if it returns false.
-
Jun 15th, 2005, 06:43 PM
#5
Frenzied Member
Re: Datagrid
Code:
private bool BindSearchData(string strSearchSql)
{
OleDbConnection scnnNW = new OleDbConnection(SQL_CONNECTION_STRING);
OleDbCommand scmd = new OleDbCommand(strSearchSql, scnnNW);
OleDbDataAdapter sda = new OleDbDataAdapter(scmd);
DataSet ds = new DataSet();
if (sda.Fill(ds) = 0)
{return false;}
dgCompany.DataSource = ds;
dgCompany.DataBind();
}
-
Jun 16th, 2005, 12:49 PM
#6
Frenzied Member
Re: Datagrid
oops! the code should read like this 
Code:
private bool BindSearchData(string strSearchSql)
{
OleDbConnection scnnNW = new OleDbConnection(SQL_CONNECTION_STRING);
OleDbCommand scmd = new OleDbCommand(strSearchSql, scnnNW);
OleDbDataAdapter sda = new OleDbDataAdapter(scmd);
DataSet ds = new DataSet();
if (sda.Fill(ds) == 0)
{return false;}
dgCompany.DataSource = ds;
dgCompany.DataBind();
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|