TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
MSK Afridi
NA
44
1.8k
System.Data.SqlClient.SqlException . cant insert
Apr 4 2020 10:42 AM
Hello there,
I am a beginner to C# and trying to insert signup data in MSSQL. but getting System.Data.SqlClient.SqlException .in System.Data.dll. I have successfully inserted data in other pages but here I am facing this issue. code is as follows
void
SignUpNewMember()
{
try
{
SqlConnection con =
new
SqlConnection(strcon);
if
(con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd =
new
SqlCommand(
"INSERT INTO member_master_tbl (full_name,dob,contact_no,email,state,city,pincode,full_address,member_id,password,account_status) values (@full_name,@dob,@contact_no,@email,@state,@city,@pincode,@full_address,@member_id,@password,@account_status)"
, con);
cmd.Parameters.AddWithValue(
"@full_name"
, TextBox1.Text.Trim());
cmd.Parameters.AddWithValue(
"@dob"
, TextBox2.Text.Trim());
cmd.Parameters.AddWithValue(
"@contact_no"
, TextBox3.Text.Trim());
cmd.Parameters.AddWithValue(
"@email"
, TextBox4.Text.Trim());
cmd.Parameters.AddWithValue(
"@state"
, DropDownList1.SelectedItem.Value);
cmd.Parameters.AddWithValue(
"@city"
, TextBox6.Text.Trim());
cmd.Parameters.AddWithValue(
"@pincode"
, TextBox7.Text.Trim());
cmd.Parameters.AddWithValue(
"@full_address"
, TextBox5.Text.Trim());
cmd.Parameters.AddWithValue(
"@member_id"
, TextBox8.Text.Trim());
cmd.Parameters.AddWithValue(
"@password"
, TextBox9.Text.Trim());
cmd.Parameters.AddWithValue(
"@account_status"
,
"pending"
);
cmd.ExecuteNonQuery();
con.Close();
Response.Write(
"<script>alert('Sign Up Successful. Go to User Login to Login');</script>"
);
}
catch
(Exception ex)
{
Response.Write(
"<script>alert('"
+ ex.Message +
"');</script>"
);
}
}
plz guide what is wrong with this code as the same code is working on other pages
Regards
Reply
Answers (
14
)
File Processing - I/O
C# - Not allowed to load local resource