输入字段后,远程数据库未更新
本文关键字:数据库 更新 字段 输入 | 更新日期: 2023-09-27 18:18:48
我制作了一个注册页面,代码如下&当我运行输入数据的代码时,我没有错误,但是当我刷新远程数据库时,字段/信息没有更新,我不知道我在哪里犯了错误……
这里我从我的网络调用我的连接字符串。配置文件。
public string GetConnectionString()
{
//sets the connection string from your web config file "ConnString" is the name of your Connection String
return System.Configuration.ConfigurationManager.ConnectionStrings["RN_DBConnectionString"].ConnectionString;
}
下面是代码,我没有得到错误,但我的远程数据库没有更新。我做错了什么…????
private void ExecuteInsert(string FName, string LName, string EID, string Password, string RPassword)字符串组织,字符串WPhone,字符串CPhone,字符串国家字符串城市,字符串状态,字符串地址{
SqlConnection conn = new SqlConnection(GetConnectionString());
string sql = "INSERT INTO RN_DB.dbo.Table (FName, LName, EID, Password, RPassword, Organization, WPhone,CPhone,Country, City, State, Address) VALUES "
+ " (@FName,@LName,@EID,@Password,@RPassword,@Organization,@WPhone,@CPhone,@Country,@City,@State,@Addess)";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter[] param = new SqlParameter[12];
//param[0] = new SqlParameter("@id", SqlDbType.NVarChar, 50);
param[0] = new SqlParameter("@FName", SqlDbType.NVarChar, 50);
param[1] = new SqlParameter("@LName", SqlDbType.NVarChar, 50);
param[2] = new SqlParameter("@EID", SqlDbType.NVarChar, 50);
param[3] = new SqlParameter("@Password", SqlDbType.NVarChar, 50);
param[4] = new SqlParameter("@RPassword", SqlDbType.NVarChar, 50);
param[5] = new SqlParameter("@Organization", SqlDbType.NVarChar, 50);
param[6] = new SqlParameter("@WPhone", SqlDbType.NVarChar, 50);
param[7] = new SqlParameter("@CPhone", SqlDbType.NVarChar, 50);
param[8] = new SqlParameter("@Country", SqlDbType.NVarChar, 50);
param[9] = new SqlParameter("@City", SqlDbType.NVarChar, 50);
param[10] = new SqlParameter("@State", SqlDbType.NVarChar, 50);
param[11] = new SqlParameter("@Address", SqlDbType.Text);
param[0].Value = FName;
param[1].Value = LName;
param[2].Value = EID;
param[3].Value = Password;
param[4].Value = RPassword;
param[5].Value = Organization;
param[6].Value = WPhone;
param[7].Value = CPhone;
param[8].Value = City;
param[9].Value = Country;
param[10].Value = State;
param[11].Value = Address;
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
}
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
}
finally
{
conn.Close();
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Pass.Text == RPass.Text)
{
Guid newGUID = Guid.NewGuid();
//call the method to execute insert to the database
ExecuteInsert(FName.Text,
LName.Text,
EID.Text, Pass.Text, RPass.Text, Org.Text, WPhone.Text, CPhone.Text,
Country.Text,
City.Text, State.Text, Address.Text);
Response.Write("Record was successfully added!");
}
else
{
Response.Write("Password's didnot match");
Pass.Focus();
}
您可能有一个错误消息,但是您在这里丢失了它:
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
}
您的msg
局部变量获得您需要的消息,但是您没有在任何地方显示它。您需要做些什么:要么在某处显示它,要么进一步抛出异常。