Как я могу решить, что ссылка на объект не установлена.
я пытаюсь этот код вставить данные в таблицу, но у меня есть ошибка
Object reference not set to an instance of an object.на
string id = cmd.Parameters["id"].Value.ToString();
мой полный код приведен ниже вместе с sql-кодом..
Что я уже пробовал:
таблица в sql.
create table addpinrequest(Appmstregno varchar(100), Qty varchar(100),Amount int, paymode varchar(100), [transaction] varchar(200), bankname varchar(200), branchname varchar(200), accountno varchar(200), ifsc varchar(100), [filename] varchar(200), msg varchar(200), id varchar(100));
хранимая процедура.
go alter procedure spaddpinrequest(@Appmstregno varchar(100), @Qty varchar(100), @Amount int, @paymode varchar(100), @transaction varchar(200), @Bankname varchar(200),@Branchname varchar(200),@Accountno varchar(200),@Ifsc varchar(100), @FileName varchar(200), @msg varchar(200),@id varchar(100)) as begin insert into addpinrequest(Appmstregno,Qty,Amount,paymode,[transaction], bankname,branchname,accountno,ifsc,[filename],msg,id) values(@Appmstregno,@Qty,@Amount,@paymode,@transaction,@Bankname,@Branchname,@Accountno,@Ifsc,@FileName,@msg,@id); end
sp-код страницы в appcode.
public static string AddPinRequest = "spaddpinrequest";
код главной страницы.
protected void Button1_Click(object sender, EventArgs e) { if (datacheck()) { int totalpackamount = Convert.ToInt32(((Label)gvPins.FooterRow.FindControl("lblTotalAmount")).Text); if (totalpackamount == Int32.Parse(txtAmount.Text)) { string fileName = string.Empty; if (uploadFile.HasFile) { fileName = "PAN/" + uploadFile.FileName; uploadFile.SaveAs(Server.MapPath(fileName)); } Int32 count = 0; DbCommand cmd = DataAccess.CreateCommand(); cmd.CommandText = SP.AddPinRequest; cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "@Appmstregno", DbType.String, _master.UserMemberId)); cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "@Qty", DbType.String, ((Label)gvPins.FooterRow.FindControl("Label1")).Text)); cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "@Amount", DbType.Int32, txtAmount.Text)); cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "@paymode", DbType.String, ddlPaymentMode.SelectedItem.Text)); cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "@transaction", DbType.String, txtTransaction.Text)); cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "@Bankname", DbType.String, txtBankName.Text)); cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "@@Accountno", DbType.String, txtAccountNo.Text)); cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "@Ifsc", DbType.String, txtIFSC.Text)); cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "@FileName", DbType.String, fileName)); cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "@msg", DbType.String, txtComment.Text)); cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "@Id", DbType.String, DBNull.Value, ParameterDirection.Output)); int i = DataAccess.ExecuteNonQuery(cmd); string id = cmd.Parameters["@Id"].Value.ToString(); if (i > 0) { foreach (GridViewRow gr in gvPins.Rows) { if (gr.RowType == DataControlRowType.DataRow) { if (((CheckBox)gr.FindControl("chkSelectPin")).Checked) { cmd = DataAccess.CreateCommandText(); cmd.CommandText = "insert into PinDetail (RequestId, Qty, PlanName, TotalAmount, PlanId, Appmstregno) values (@RequestId, @Qty, @PinValue, @PinValue, @PlanId, @Appmstregno)"; cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "PinValue", DbType.String, gr.Cells[2].Text)); cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "PlanId", DbType.String, gr.Cells[1].Text)); cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "Qty", DbType.String, ((TextBox)gr.FindControl("txtNoOfPins")).Text)); cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "Appmstregno", DbType.String, _master.UserMemberId)); cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "RequestId", DbType.String, id)); count += DataAccess.ExecuteNonQuery(cmd); cmd.Parameters.Clear(); } } } } if (count > 0) { reset(); Message.Show("Thanks, Request Send successfully. We will contact you soon.."); } else { Message.Show("Sorry!! There is something wrong please contact Administrator."); } } else { Message.Show("Sorry!!! Amount is less Then or Not equal to Total pin cost"); } } }
<pre lang="c#">