zoukankan      html  css  js  c++  java
  • C#—连接SQLserver数据库,并执行查询语句代码

    //字段ArticleID,ArticleName,ArticleNumber,Unit,Weight,Price,Currency,IsIuggage,IsQuarantine
    string str = myArticleInfo[i].ArticleID.ToString();//取物品编码进行查询
     string strconn = "Data Source=192.168.100.132;Initial Catalog=CustomsPlatform;User ID=sa;password=max_123456";  //链接语句
    
     SqlConnection conn = new SqlConnection(strconn);    ////连接到引入的数据库
    conn.Open();// 打开数据库连接
    SqlCommand sqlcmd = new SqlCommand();//创建 Command 对象
    sqlcmd.CommandText = string.Format(@"select ArticleID,ArticleName,ArticleNumber,Unit,Weight,Price,Currency,IsIuggage,IsQuarantine 
                                                            from [CustomsPlatform].[dbo].[TB_ArticleInfo] where ArticleID = '{0}'", str);//执行查询语句
    sqlcmd.Connection = conn;
    SqlDataAdapter adp = new SqlDataAdapter(sqlcmd);
     DataTable dt = new System.Data.DataTable();
    adp.Fill(dt);
    this.SortListViewData.DataSource = dt;
    conn.Close();// 关闭数据库连接
    

      

  • 相关阅读:
    org-mode
    MediaWiki
    Creole
    AsciiDoc
    markdown
    图像对比度调整的simulink仿真总结
    Altera的几个常用的Synthesis attributes(转载)
    红外发送接收电路(转载)
    使用反相器的rc振荡电路
    两个小电路
  • 原文地址:https://www.cnblogs.com/ganbei/p/11274548.html
Copyright © 2011-2022 走看看