Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C#
string sql = "select [DocEntry],[JobCardNo],[ITEMNAME],[OD] ,[PlanQty],[FinalInspectionRemarks] ,[OrderDate] ,[Division],[ChervonSet],[Profile] from SAPProduction.FactoryProductionData WHERE JobCardNo ='" + findjobsap.Text.ToString() + "'";
                    SqlDataAdapter da1 = new SqlDataAdapter(sql, objConn1);
                    DataSet ds1 = new DataSet();
                    objConn1.Open();
                    da1.Fill(ds1, "FactoryProductionData");
                    dataGridView1.DataSource = ds1;
                    //dataGridView1.DataBind();
                    dataGridView1.DataMember = "FactoryProductionData";
                    objConn1.Close();
Posted
Updated 16-Jan-13 0:28am
v4
Comments
Vani Kulkarni 16-Jan-13 3:19am    
Please elaborate. What is the issue here?
Master Vinu 16-Jan-13 3:20am    
iam filling datagridview on search of jobcardno from database, but if jobcardno not found in database i want some message should be thrown

Well you can check the dataset ds1 if it is null.

C#
string sql = "select [DocEntry],[JobCardNo],[ITEMNAME],[OD] ,[PlanQty],[FinalInspectionRemarks] ,[OrderDate] ,[Division],[ChervonSet],[Profile] from SAPProduction.FactoryProductionData WHERE JobCardNo ='" + findjobsap.Text.ToString() + "'";
SqlDataAdapter da1 = new SqlDataAdapter(sql, objConn1);
DataSet ds1 = new DataSet();
objConn1.Open();
da1.Fill(ds1, "FactoryProductionData");

if (ds1 == null)
{  
    objConn1.Close();
    return;
}

dataGridView1.DataSource = ds1;
dataGridView1.DataMember = "FactoryProductionData";
objConn1.Close();
 
Share this answer
 
C#
string sql = "select [DocEntry],[JobCardNo],[ITEMNAME],[OD] ,[PlanQty],[FinalInspectionRemarks] ,[OrderDate] ,[Division],[ChervonSet],[Profile] from SAPProduction.FactoryProductionData WHERE JobCardNo ='" + findjobsap.Text.ToString() + "'";
SqlDataAdapter da1 = new SqlDataAdapter(sql, objConn1);
DataSet ds1 = new DataSet();
objConn1.Open();
da1.Fill(ds1, "FactoryProductionData");
 
if (ds1 == null)
{  
    objConn1.Close();
    return;
}
 
dataGridView1.DataSource = ds1;
dataGridView1.DataMember = "FactoryProductionData";
objConn1.Close();
C#
if (dataGridView1.Rows.Count <= 0)
            {
                MessageBox.Show("");
            }
 
Share this answer
 
v3
Comments
Master Vinu 16-Jan-13 3:22am    
please make changes in code pls
Add a condition before you bind the grid with dataset as below:

C#
if (ds1.Tables[0].Rows.Count > 0)
{
   datagridview.DataSource = ds1;
   datagridview.DataBind();
}
else
{
    datagridview.Visible = false;
    //Show a label or message
    MessageBox.Show("Job Card not found");     
}
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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