1.App.config
<configuration>
<appSettings>
<add key="dburl" value=""/>
<add key="dbusername" value=""/>
<add key="dbpassword" value=""/>
<add key="dbname" value="AIS20191213233420"/>
</appSettings>
</configuration>
static string dburl = ConfigurationManager.AppSettings["dburl"];
static string dbusername = ConfigurationManager.AppSettings["dbusername"];
static string dbpassword = ConfigurationManager.AppSettings["dbpassword"];
static string dbname = ConfigurationManager.AppSettings["dbname"];
public static string ConStr = "server= "+ dburl + "; uid="+ dbusername + "; pwd="+ dbpassword + "; database="+ dbname;
SqlConnection con = new SqlConnection(ConStr);
con.Open();
String sql = "select b.FNUMBER as FNUMBER, c.FNAME as FNAME from [AIS20191213233420].[dbo].[T_ENG_BOMCHILD] child left join [AIS20191213233420].[dbo].T_BD_MATERIAL b on child.FMATERIALID = b.FMATERIALID left join [AIS20191213233420].[dbo].T_BD_MATERIAL_L c on b.FMATERIALID = c.FMATERIALID where c.FLOCALEID = 2052 and b.FNUMBER = '" + bom.BomCode + "'";
//创建命令对象,指定要执行sql语句与连接对象conn
SqlCommand cmd = new SqlCommand(sql, con);
//执行查询返回结果集
SqlDataReader sdr = cmd.ExecuteReader();
//下移游标,读取一行,如果没有数据了则返回false
while (sdr.Read())
{
this.listBox2.Items.Add(DateTime.Now.ToLocalTime().ToString() + " 子项物料编码" + bom.BomCode + "已存在…");
CheckMaterialName(childCount, bom);
childCount++;
}
// 连接关闭
con.Close();