我相信这个问题是在几个月前被问到的,但我相信我的情况有所不同,同样的规则也许不适用.
每次我执行此方法时都会弹出相同的错误.位置0没有行.如果我将[0]改为[1]或[15]; [1]等处没有行.这是否意味着我的数据库连接都没有?我应该写一些if语句来确定行是否在那里?
public bool UpdateOrderToShipped(string order)
{
orderNumber = order;
string batch = ConfigurationManager.AppSettings["SuccessfulOrderBatch"];
string statement = "UPDATE SOP10100 SET BACHNUMB = '"+ batch +"' WHERE SOPNUMBE = @SOPNUMBE";
SqlCommand comm = new SqlCommand(statement, connectionPCI);
comm.Parameters.Add("SOPNUMBE", orderNumber);
try
{
comm.Connection.Open();
comm.ExecuteNonQuery();
comm.Connection.Close();
}
catch(Exception e)
{
comm.Connection.Close();
KaplanFTP.errorMsg = "Database error: " + e.Message;
}
statement = "SELECT SOPTYPE FROM SOP10100 WHERE SOPNUMBE = @SOPNUMBE";
comm.CommandText = statement;
SqlDataAdapter da = new SqlDataAdapter(comm);
DataTable dt = new DataTable();
da.Fill(dt); …Run Code Online (Sandbox Code Playgroud) 有一个类似的问题在stackoverflow上没有答案,但我相信我非常接近解决它.但基本上,我的sql语句返回多个值,但标签中只显示一个值,而它应该是4或5个值.
protected void btnPopulate_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strings.settings.connectionString);
SqlCommand command = new SqlCommand("SELECT ID FROM dbo.MDRMASTER WHERE MASTERPID = @MASTERPID",con);
command.Parameters.Add("@MASTERPID", SqlDbType.NVarChar).Value = txtMASTERID.Text;
con.Open();
SqlDataReader dr = command.ExecuteReader();
while (dr.Read())
{
string ID = dr["ID"].ToString();
lblIDs.Text = ID;
}
con.Close();
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.谢谢!