初学存储过程遇到问题====
类中的 代码:public class save
{
public static int abis_JCJAddMember(string JCG_RYBH,string JCG_BMBH)
{
SqlConnection sc = new SqlConnection(ConfigurationManager.AppSettings["ConnStr"]);
SqlCommand cmd = new SqlCommand("abis_JCJAddMember", sc);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@JCG_RYBH", JCG_RYBH);
cmd.Parameters.AddWithValue("@JCG_BMBH", JCG_BMBH);
cmd.Parameters.Add(new SqlParameter("@RETURN_VALUE", SqlDbType.Int, 4, ParameterDirection.ReturnValue, false, 0, 0, "", DataRowVersion.Current, null));
sc.Open();
cmd.ExecuteNonQuery();
int rst = (int)cmd.Parameters["@RETURN_VALUE"].Value;
sc.Close();
cmd.Parameters.Clear();
cmd.Dispose();
return rst;
}
}
、、、、、、、、、、、、、、、、、、、
在asp.net
protected void Button1_Click(object sender, EventArgs e)
{
string RYBH=TextBox1.Text.ToString();
string BMBH = TextBox2.Text.ToString(); ;
int iSave=save.abis_JCJAddMember(RYBH,BMBH);
}
////////////////////////
错误提示: ConnectionString 属性尚未初始化。
我想用上面的程序 实现 利用存储过程插入数据,
--------------------编程问答-------------------- ConnectionString 在哪用到了? --------------------编程问答-------------------- 错误提示:啊
web。config
<connectionStrings>
<add name="ConnStr" connectionString="Data Source=.;Initial Catalog=test;Persist Security Info=True;User ID=sa;Password=4321" providerName="System.Data.SqlClient"/>
</connectionStrings> --------------------编程问答-------------------- <connectionStrings>
<appSettings>
<add name="ConnStr" connectionString="Data Source=.;Initial Catalog=test;Persist Security Info=True;User ID=sa;Password=4321" providerName="System.Data.SqlClient"/>
</appSettings>
</connectionStrings> --------------------编程问答-------------------- 试试!~
SqlConnection sc = new SqlConnection(ConfigurationManager.AppSettings["ConnStr"].ToString());
<appSettings>
<add key="connectionString" Value="Data Source=.;Initial Catalog=test;Persist Security Info=True;User ID=sa;Password=4321" providerName="System.Data.SqlClient"/>
</appSettings>
--------------------编程问答-------------------- SqlConnection sc = new SqlConnection(连接字符串)试一试,如果好使就是CONFIG中的问题
将CONFIG中改为
<appSettings>
<add key="conStr" Value="Data Source=.;Initial Catalog=test;Persist Security Info=True;User ID=sa;Password=4321" providerName="System.Data.SqlClient"/>
</appSettings>
程序中改为
SqlConnection sc = new SqlConnection(ConfigurationSettings.AppSettings["conStr"])
--------------------编程问答-------------------- 或者
<appSettings>
<add key="conStr" Value="server=.;uid=sa;pwd=4321;database=数据库名"/>
</appSettings>
补充:.NET技术 , ASP.NET