如果jobcardno不存在....需要消息....在Windows窗体中 [英] need message if jobcardno not exsist .... in windows form

查看:89
本文介绍了如果jobcardno不存在....需要消息....在Windows窗体中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();

推荐答案

您可以检查数据集ds1是否为空。



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();


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("");
            }


在使用数据集绑定网格之前添加条件,如下所示:



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");     
}


这篇关于如果jobcardno不存在....需要消息....在Windows窗体中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆