i have this code
but the data is not save in my local database please help me.
(
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
enum Insert_DATA{string Email, string Password, string Repeat_Password}
{
//String s = "Data Source=HAFEEZ-PMO;Initial Catalog=PPG_Biller;Integrated Security=true;providerName=System.Data.SqlClient";
string s = "Server=HAFEEZ-PMO;Database=AHBKS;User ID=hafeez;Password=sa123;Trusted_Connection=False;";
using (SqlConnection connection = new SqlConnection(hafeez))
{
try
{
connection.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = connection;
cmd.CommandText = "SP_INSERT_DATA";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@Password", Password);
cmd.Parameters.AddWithValue("@Repeat_Password", Repeat_Password);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (connection.State == ConnectionState.Open)
connection.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Insert_Data("12345", "12345", 1);
}
}
}
)

Amit MohantyRank #112 · 20K reputationPosted Oct 11, 2022, 6:56 AM EDT
Firstly check your sqlconnection. you have stored your connection srting in "s" variable, but passed "hafeez" to sqlconnection.
Secondly check your stored procedure is created correctly in your database in which you want to insert the data.
Sam HobbsRank #107 · 20.5K reputationPosted Oct 13, 2022, 2:43 AM EDT
Are you catching exceptions? The catch block you show here says:
throw ex;but we do not see what happens after that.
Also, you have:
enum Insert_DATA{string Email, string Password, string Repeat_Password}where I would expect a method declaration to be. I do not know what that is; it looks strange to me.