问题描述
Hii我是asp.net的新手
我在同一页面上调用了两个存储过程,两者都是在回发之前调用的。第一个过程调用用于将数据绑定到GridView,第二个用于下拉列表。我为这两个过程传递@Flag。当程序执行一个绑定方法为Gridview正确执行但在bindDll它给出错误@Flag发送多次。
任何人都可以帮助我
谢谢。
*******************
这是我的代码
******** ***********************************
Hii I'm New in asp.net
I call two stored Procedure at same page ,both are call before post back. First procedure call is use to bind data to GridView and second one is used for dropdown list .I pass a @Flag for both procedure. When program execute a bind Method for Gridview execute properly but at bindDll it gives error @Flag send Multiple time.
Can anybody help me
Thank you.
*******************
This is my code
***************************************
String strConnString = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
SqlConnection con;
SqlCommand cmd = new SqlCommand();
string @value;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridView();
Binddl();
}
}
private void BindGridView()
{
con = new SqlConnection(strConnString);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Flag", 11);
cmd.CommandText = "StoreProcedureSelect";
cmd.Connection = con;
try
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
//GridView1.DataSource = ds;
//GridView1.DataBind();
if (ds.Tables[0].Rows.Count == 0)
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
grdvwParts.DataSource = ds;
grdvwParts.DataBind();
int columncount = grdvwParts.Rows[0].Cells.Count;
grdvwParts.Rows[0].Cells.Clear();
grdvwParts.Rows[0].Cells.Add(new TableCell());
grdvwParts.Rows[0].Cells[0].ColumnSpan = columncount;
grdvwParts.Rows[0].Cells[0].Text = "No Records Found";
}
else
{
grdvwParts.DataSource = ds;
grdvwParts.DataBind();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}
}
public void Binddl()
{
try
{
con = new SqlConnection(strConnString);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Flag",1);
cmd.CommandText = "SPPartTable";
cmd.Connection = con;
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
ddlsection.DataSource = dt;
ddlsection.DataBind();
ddlsection.DataTextField = "sdesc";
ddlsection.DataValueField = "sec_id";
ddlsection.DataBind();
}
catch (Exception e)
{
throw e;
}
finally
{
con.Close();
con.Dispose();
}
}
推荐答案
con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand("SPPartTable", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Flag",1);
注意:当您使用适配器$ c时,无需打开和关闭连接$ c>,因为它们会自动为您打开和关闭。
NOTE: No need to open and close connections when you are using the Adapters
, because they automatically open and close for you.
这篇关于@Flag不是Procedure SPPartTable的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!