Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to 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 15-Jan-13 21:06pm
Edited 16-Jan-13 0:28am
v4
Comments
Vani Kulkarni at 16-Jan-13 3:19am
   
Please elaborate. What is the issue here?
vinayak chavan at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Well you can check the dataset ds1 if it is null.
 
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();
 
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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();
if (dataGridView1.Rows.Count <= 0)
            {
                MessageBox.Show("");
            }
  Permalink  
v3
Comments
vinayak chavan at 16-Jan-13 3:22am
   
please make changes in code pls
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Add a condition before you bind the grid with dataset as below:
 
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");     
}
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 490
1 Gihan Liyanage 338
2 ChauhanAjay 180
3 Vinay Mistry 160
4 Sergey Alexandrovich Kryukov 153
0 Sergey Alexandrovich Kryukov 9,011
1 OriginalGriff 7,941
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100