我有一個SQL Server數據庫表EmpDetails
,它包含兩個行值。我想將這些值保存到另一個表中。但根據我的代碼,我只能得到第一行的值。如何從我的EmpDetails
表中獲取所有行值。如何在字符串中設置數據庫表值?
我的示例代碼:
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
SqlCommand cmd = new SqlCommand ("select e.MachID,e.Name,e.EmpCode,T.TypeName from EmpDetails e,EmpType t where e.EtypeID=t.EtypeID and e.Deptid='" + dddep.SelectedItem.Value + "'",conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
string name = Convert.ToString(ds.Tables[0].Rows[0]["Name"]);
string code = Convert.ToString(ds.Tables[0].Rows[0]["EmpCode"]);
string type = Convert.ToString(ds.Tables[0].Rows[0]["TypeName"]);
通過使用'ds.Tables [0] .Rows [1] [ 「XYZ」]'和存儲那些成不同的變量? – User 2014-11-06 05:51:52