添加和更新问题 [英] problem with add and update
本文介绍了添加和更新问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
选择语句正常工作,但我在同一程序中添加和更新数据库有问题.我使用此代码添加:
hi all
the select statement work correctly but i have problem with add and update to database in same program. i used this code to add:
UserInformation.InsertUserWithProcedure(textBox1.Text, textBox2.Text);
public static void InsertUserWithProcedure(string UserName, string Password)
{
SqlConnection con = new SqlConnection();
SqlCommand com = new SqlCommand();
con.ConnectionString = DataAccess.str;
con.Open();
com.Connection = con;
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "insert_user";
com.Parameters.Add("@UserName", SqlDbType.NVarChar, 300).Value = UserName;
com.Parameters.Add("@Password", SqlDbType.NVarChar,300).Value = Password;
com.ExecuteNonQuery();
con.Close();
}
而存储过程是
and the stored procedure is
ALTER procedure [dbo].[insert_user]
@Username nvarchar(300),@Password nvarchar(300)
as
insert into UserData (Username,Password) values (@Username,@Password)
而且我不知道怎么了
请帮助
谢谢
and i do not know what is the wrong
please help
thanks
推荐答案
尝试 ^ ]而不是链接.
Try AddWithValue[^] instead of linking.
请尝试下面的代码对我有用
Hi,
Please Try the code below it works for me
public static void InsertUserWithProcedure(string UserName, string Password)
{
SqlConnection con = new SqlConnection(DataAccess.str);
con.Open();
SqlCommand com = new SqlCommand("insert_user", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@UserName", UserName);
com.Parameters.AddWithValue("@Password", Password);
com.ExecuteNonQuery();
con.Close();
}
您的代码似乎也对我有用,我已经对其进行了测试
因此,如果您对此代码的选择代码有疑问,请附加您的代码以尝试解决您面临的问题
问候,
艾哈迈德·曼杜尔(Ahmed Mandour)
your code seems also to work for me and i have tested it
so if you have a problem with select code with this code please attach your code to try to solve the issue you are facing
Regards,
Ahmed Mandour
这篇关于添加和更新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文