I have used the store procedure in MS-Sql for inserting for particular page it is working fine but I also need the same store procedure for other page it is finding me the error.
protected void btnsubmitt_Click(object sender, EventArgs e)
{
ArrayList arParameters = ReturnParameter();
DataSet dsInsertProfile = objadmin.GetGridData(arParameters, objconstant.sSP_INSERT_PROFILE);
if (int.Parse(dsInsertProfile.Tables[0].Rows[0].ItemArray[0].ToString()) == 0)
{
pnlProfile.Visible = false;
pnlThank.Visible = true;
lblThank.Text = "Your profile have been successfully saved.";
}
else
{
lblThank.Text = "Your profile is not saved, please try again later.";
}
}
public ArrayList ReturnParameter()
{
Int64 email = Convert.ToInt64(txtemail.Text.ToString());
ArrayList arSample = new ArrayList();
Object[] c_email_id = new Object[3] { "@strEmailID", "varchar", email};
arSample.Add(c_email_id);
return arSample;
}
public DataSet GetGridData(ArrayList dbArray, string sSpName)
{
DataSet dsDataSet = new DataSet();
dsDataSet = datamanager.GetGridData(dbArray, sSpName);
return dsDataSet;
}
public static DataSet GetGridData(ArrayList dbArray, string sSpName)
{
DataSet dsDataSet = new DataSet();
SqlConnection cn = createConnection();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = sSpName;
object objPrMtrName;
object objSqlType;
object objPrMtrVal;
int i;
for (i = 0; i < dbArray.Count; i++)
{
objPrMtrName = ((object[])(dbArray[i]))[0];
objSqlType = ((object[])(dbArray[i]))[1];
objPrMtrVal = ((object[])(dbArray[i]))[2];
cmd.Parameters.Add(objPrMtrName.ToString(), GetSqlDataType(objSqlType.ToString())).Value = objPrMtrVal;
}
cmd.Connection = cn;
try
{
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dsDataSet);
return dsDataSet;
}
catch (Exception ex)
{
throw ex;
}
finally
{
cn.Close();
cn.Dispose();
}
}
Mystore procedure
ALTER Procedure [dbo].[spInsert_profile]
( @strEmailID varchar(200)
)
AS
BEGIN
DECLARE @intEmail INT
SET @intEmail = (SELECT COUNT(*) FROM gdt_Users WHERE [c_email_id]=@strEmailID)
IF @intEmail = 0
BEGIN
Insert into gdt_Users([c_email_id],[d_modified_dttm],[d_created_dttm])values(@strEmailID,GETDATE(),GETDATE())
SELECT @intEmail
END
ELSE
BEGIN
SELECT @intEmail
END
END
Here, I was facing a problem. It was throwing an exception
ERROR: Failed to convert parameter value from string to Int64
So, I’ve add this code
Int64 email = Convert.ToInt64(txtemail.Text.ToString());
in arraylist returnparameter() method. Then, it threw that exception
ERROR: Input string was not in correct format
How can I solve this? Can you help me?
In your code I can find Convert.ToInt64 only at one place which is
You would not be passing valid number to Convert.ToInt64( as
txtemailwill have string not a number. You should give a number in txtemail or use the correct textbox for converting the string to int64.