Wrox Programmer Forums
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 19th, 2009, 08:50 PM
Authorized User
 
Join Date: Jun 2009
Posts: 30
Thanks: 13
Thanked 0 Times in 0 Posts
Default add record into table

hi....after i add all the records in textbox ,i click post and pay....but it does not add any record into the table ,does not show any error and does not show message that i add the record into the table.....what is the error....can anybody correct for me?

this is the code
protectedvoid Button3_Click(object sender, EventArgs e)
{
SqlConnection con;
SqlConnection connect;
SqlCommand cmdInsert;
SqlDataReader dtrJob;
SqlDataReader dtrCredit;
SqlCommand cmdRead;
SqlCommand cmdCredit;
SqlCommand cmdUpdate;
string newJbId = "J" + newJobID().ToString("D6");
string strEmp = Session["Employer"].ToString();
string message="";
string strUpdate = "";
double creditEmp = 0.00;
SqlCommand cmdInsertProfit;
SqlConnection connection;

con =
newSqlConnection(ConfigurationManager.ConnectionStrings["tarStreetConnectionString1"].ConnectionString);
connection =
newSqlConnection(ConfigurationManager.ConnectionStrings["tarStreetConnectionString1"].ConnectionString);
connect =
newSqlConnection(ConfigurationManager.ConnectionStrings["tarStreetConnectionString1"].ConnectionString);

con.Open();
connect.Open();
string check = "Select * from JobPost Where Job_ID = @id";
string credit = "Select * from Employer Where Employer_Id=@employer";
cmdRead =
newSqlCommand(check, con);
cmdCredit =
newSqlCommand(credit, connect);

cmdRead.Parameters.AddWithValue(
"@id", newJbId);
cmdCredit.Parameters.AddWithValue(
"@employer", Session["Employer"].ToString());
dtrJob = cmdRead.ExecuteReader();
dtrCredit = cmdCredit.ExecuteReader();
if (dtrJob.HasRows)
{
lblMsg.Text =
"JobPost already Exist!";
}
else
{
if (dtrCredit.Read())
{
creditEmp=
Convert.ToDouble(dtrCredit["Employer_Credit"]);
if (creditEmp >= 10.00)
{

con.Close();
con.Open();
string insertJob = "Insert Into JobPost(Job_Id,Job_Desc,Job_Specialization,Job_Min Qualification,Job_PositionLevel,Job_Title,Job_CmpN ame,Job_Location,Job_Employment,YrsOfExperience,Jo b_CmpIntroduction,Employer_Id,job_Month)Values(@id ,@desc,@Special,@min_Qua,@position,@title,@cmpName ,@location,@job_Employ,@yrsExpe,@job_intro,@empid, @month)";
cmdInsert =
newSqlCommand(insertJob, con);

cmdInsert.Parameters.AddWithValue(
"@id", newJbId);
cmdInsert.Parameters.AddWithValue(
"@desc", TextBox9.Text);
cmdInsert.Parameters.AddWithValue(
"@Special", DropDownList6.SelectedItem.Text);//DropDownList6.SelectedItem.Text
cmdInsert.Parameters.AddWithValue("@min_Qua", DropDownList10.SelectedItem.Text);
cmdInsert.Parameters.AddWithValue(
"@position", DropDownList5.SelectedItem.Text);
cmdInsert.Parameters.AddWithValue(
"@title", txtPosition.Text);
cmdInsert.Parameters.AddWithValue(
"@cmpName", TextBox10.Text);
cmdInsert.Parameters.AddWithValue(
"@location", DropDownList8.SelectedItem.Text);
cmdInsert.Parameters.AddWithValue(
"@job_Employ", RadioButtonList1.SelectedItem.Text);//CheckBoxList1.SelectedItem.Text
cmdInsert.Parameters.AddWithValue("@yrsExpe", TextBox7.Text);
cmdInsert.Parameters.AddWithValue(
"@job_intro", TextBox11.Text);
cmdInsert.Parameters.AddWithValue(
"@empid", strEmp);
cmdInsert.Parameters.AddWithValue(
"@month", DateTime.Now.Month.ToString());
cmdInsert.ExecuteNonQuery();
con.Close();
message =
"Record Added ! </br>";
creditEmp -= 10;
strUpdate =
"Update Employer set Employer_Credit=@cre Where Employer_Id=@eID";
cmdUpdate =
newSqlCommand(strUpdate, connect);
connect.Close();

connect.Open();
cmdUpdate.Parameters.AddWithValue(
"@eID", strEmp);
cmdUpdate.Parameters.AddWithValue(
"@cre", Convert.ToString(creditEmp));
cmdUpdate.ExecuteNonQuery();
message +=
"Your balance : ";
message +=
Convert.ToString(creditEmp);
connect.Close();
connection.Open();
string insertProfit = "Insert Into Profit(Related_Id,Profit_Type,Profit_Get,Profit_Mo nth)Values(@rel_id,@type,@gain,@ProMonth)";
cmdInsertProfit =
newSqlCommand(insertProfit, connection);
cmdInsertProfit.Parameters.AddWithValue(
"@rel_id", newJbId);
cmdInsertProfit.Parameters.AddWithValue(
"@type", "Job");
cmdInsertProfit.Parameters.AddWithValue(
"@gain", 10.00);
cmdInsertProfit.Parameters.AddWithValue(
"@ProMonth", DateTime.Now.Month.ToString());
cmdInsertProfit.ExecuteNonQuery();
connection.Close();
}
else
{
message = dtrCredit[
"Employer_Credit"].ToString () + "Not Enough Credit . Please reload your Credit!";

}
}
else
{
lblMsg.Text =
"Cannot found ";
}

}
lblMsg.Text = message ;
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Record to table from form AlForum29 Access VBA 2 January 2nd, 2013 09:46 PM
Find Last Record and Add new keyed record causualuser Access VBA 3 February 9th, 2009 08:24 AM
Add record to another table with radiobutton Dejitan ASP.NET 1.0 and 1.1 Basics 8 January 11th, 2007 09:24 AM
ADO record copy and add to table Freddyfred Access 2 February 16th, 2005 10:36 PM
Error 3201: Cannot add record in child form/table HomeShow Access VBA 0 October 5th, 2004 09:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.