使用where語句訪問數據庫時where語句用上文中以及定義過的變量來查詢。
string sql3 = string.Format("update Ships set ContainerNum='"+list1[0].ContainerNum+"' where Name='"+list[0].ShipName+"'");
Ships是表名 ContainerNum是表中字段名
list1[0].ContainerNum是上文的一個Int 類型變量,list[0].ShipName是上文的string類型變量
只需要在sql語句的雙引號內對變量進行操作,即
(“select * from 表名 where 字段名= ‘“+ 變量名+”’ ”) 需要注意的是:‘“+ 變量名+”’ 要用兩個單引號括住兩個雙引號
