hello,
I have a problem with update user info, when i try update user info and if i add in his name like kankon, i change name to kankons then i press update its add me
Do i need add something else?
i want add a message u must register first or there is no name for kankons in data please contact Admin
SQL
USE [cm]
GO
/****** Object: StoredProcedure [dbo].[update_User_C3] Script Date: 22/11/2022 10:07:28 م ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
alter PROCEDURE [dbo].[update_UserS]
(
@name NVARCHAR(MAX)=NULL,
@fileid NVARCHAR(MAX)=NULL,
@civilid NVARCHAR(MAX)=NULL,
@Countries NVARCHAR(MAX)=NULL,
@States NVARCHAR(MAX)=NULL,
@Cities NVARCHAR(MAX)=NULL,
@mobile NVARCHAR(MAX)=NULL,
@jop NVARCHAR(MAX)=NULL
)
AS
BEGIN
SET NOCOUNT ON;
IF EXISTS(SELECT id FROM Table_infoname WHERE name = @name)
BEGIN
SELECT -1 -- name exists.
END
ELSE IF EXISTS(SELECT id FROM Table_infoname WHERE civilid = @civilid)
BEGIN
SELECT -2 -- civilid exists.
END
ELSE IF EXISTS(SELECT id FROM Table_infoname WHERE fileid = @fileid)
BEGIN
SELECT -3 -- fileid exists.
END
ELSE
BEGIN
UPDATE Table_infoname
SET
name=@name,
fileid=@fileid,
civilid=@civilid,
Countries=@Countries,
States=@States,
Cities=@Cities,
jop=@jop,
mobile=@mobile
where civilid=@civilid
end
END
code behind c#
protected void Button28_Click(object sender, EventArgs e)
{
int Id = 0;
string constr = ConfigurationManager.ConnectionStrings["cmConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("update_UserS"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.CommandType = CommandType.StoredProcedure;
if (!string.IsNullOrEmpty(fName.Text.Trim()))
{
cmd.Parameters.AddWithValue("@name", fName.Text.ToString());
}
if (!string.IsNullOrEmpty(ffileid.Text.Trim()))
{
cmd.Parameters.AddWithValue("@fileid", ffileid.Text.ToString());
}
if (!string.IsNullOrEmpty(fcivilid.Text.Trim()))
{
cmd.Parameters.AddWithValue("@civilid", fcivilid.Text.ToString());
}
if (!string.IsNullOrEmpty(mobile.Text.Trim()))
{
cmd.Parameters.AddWithValue("@mobile", mobile.Text.ToString());
}
if (!string.IsNullOrEmpty(joptitel.Text.Trim()))
{
cmd.Parameters.AddWithValue("@jop", joptitel.Text.Trim());
}
if (!string.IsNullOrEmpty(ddlCountries2.Text.Trim()))
{
cmd.Parameters.AddWithValue("@Countries", ddlCountries2.Text.ToString());
}
if (!string.IsNullOrEmpty(ddlStates2.Text.Trim()))
{
cmd.Parameters.AddWithValue("@States", ddlStates2.Text.ToString());
}
if (!string.IsNullOrEmpty(ddlCities2.Text.Trim()))
{
cmd.Parameters.AddWithValue("@Cities", ddlCities2.Text.ToString());
}
cmd.Connection = con;
con.Open();
Id = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
}
string message = string.Empty;
switch (Id)
{
case -1:
message = "اسم المستخدم موجود مسبقا";
break;
case -2:
message = "الرقم المدني مستخدم";
break;
case -3:
message = "رقم الملف مستخدم";
break;
default:
message = "تم تحديث بيانات الموظف بنجاح\\nاسم الموظف : " + fName.Text.ToString();
break;
}
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
}
}
}