.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ADO.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Query not being executed

Posted By: archana     Posted Date: January 29, 2010    Points:2   Category :ADO.Net
Hi,

I need to insert values from the frontend into a mysql table. I am using a 3 layer architecture. the below is the code that is written in my dataaccess layer. the query is not being executed. Can you please help with this.

public int Insert(List<EmployeeUInfo> objInsert)
{
try
{
DataTable dtInsertRow = new DataTable();
DataColumn dc = new DataColumn();
dtInsertRow.Columns.Add("employeeid");
dc = new DataColumn();
dtInsertRow.Columns.Add("employeename");
dc = new DataColumn();
dtInsertRow.Columns.Add("business");
dc = new DataColumn();
dtInsertRow.Columns.Add("emailid");
dc = new DataColumn();
dtInsertRow.Columns.Add("phoneno");

foreach (EmployeeUInfo objIDetails in objInsert)
{
DataRow dr = dtInsertRow.NewRow();
dtInsertRow.Rows.Add(objIDetails.employeeid, objIDetails.employeename,objIDetails.business, objIDetails.emailid, objIDetails.phoneno);
}

MySqlConnection con = new MySqlConnection(ConfigurationManager.AppSettings["ConStr"]);

string query = "insert into employee(employeeid,employeename,business,emailid,phoneno) values(@employeeid,@employeename,@business,@emailid,@phoneno)";
MySqlCommand cmd = new MySqlCommand(query, con);




//MySqlCommand cmd = new MySqlCommand();
//MySqlDataAdapter adap = new MySqlDataAdapter("insert into employee(employeeid,employeename,business,emailid,phoneno) values(@employeeid,'@employeename','@business','@emailid',@phoneno)",con);


cmd.Parameters.AddWithValue("@employeeid", SqlDbType.Int).Value = Convert.ToInt32(dtInsertRow.Rows[0]["employeeid"]);
cmd.Parameters.AddWithValue("@employeename", SqlDbType.VarChar).Value = Convert.ToString(dtInsertRow.Rows[0]["employeename"]);
cmd.Parameters.AddWithValue("@business", SqlDbType.VarChar).Value = Convert.ToString(dtInsertRow.Rows[0]["business"]);
cmd.Parameters.AddWithValue("@emailid", SqlDbType.VarChar).Value = Convert.ToString(dtInsertRow.Rows[0]["emailid"]);
cmd.Parameters.AddWithValue("@phoneno", SqlDbType.Int).Value = Convert.ToInt32(dtInsertRow.Rows[0]["phoneno"]);

con.Open();
MySqlDataAdapter da = new MySqlDataAdapter();
da.InsertCommand = new MySqlCommand(query, con);
da.InsertCommand = cmd;


}
catch
{

throw;

}

finally
{

con.Close();
con.Dispose();
}
int j = 0;
return j;

}

Responses
Author: Sagar Pardeshi             
Posted Date: January 29, 2010     Points: 5   

MySqlConnection con = new MySqlConnection(ConfigurationManager.AppSettings["ConStr"]);

string query = "insert into employee(employeeid,employeename,business,emailid,phoneno) values(@employeeid,@employeename,@business,@emailid,@phoneno)";
MySqlCommand cmd = new MySqlCommand(query, con);
cmd.ExecuteNonQuery();

Author: archana             
Posted Date: January 29, 2010     Points: 5   

even though i use the above stmt the query is not being executed

Author: Sagar Pardeshi             
Posted Date: January 29, 2010     Points: 5   

tell me what u can do exactly

Author: Sagar Pardeshi             
Posted Date: January 29, 2010     Points: 5   

send me ur code remove ur comment code ok

Author: archana             
Posted Date: January 29, 2010     Points: 5   

public int Insert(List<EmployeeUInfo> objInsert)
{
try
{
DataTable dtInsertRow = new DataTable();
DataColumn dc = new DataColumn();
dtInsertRow.Columns.Add("employeeid");
dc = new DataColumn();
dtInsertRow.Columns.Add("employeename");
dc = new DataColumn();
dtInsertRow.Columns.Add("business");
dc = new DataColumn();
dtInsertRow.Columns.Add("emailid");
dc = new DataColumn();
dtInsertRow.Columns.Add("phoneno");

foreach (EmployeeUInfo objIDetails in objInsert)
{
DataRow dr = dtInsertRow.NewRow();
dtInsertRow.Rows.Add(objIDetails.employeeid, objIDetails.employeename,objIDetails.business, objIDetails.emailid, objIDetails.phoneno);
}

MySqlConnection con = new MySqlConnection(ConfigurationManager.AppSettings["ConStr"]);

string query = "insert into employee(employeeid,employeename,business,emailid,phoneno) values(@employeeid,@employeename,@business,@emailid,@phoneno)";
MySqlCommand cmd = new MySqlCommand(query, con);
cmd.Parameters.AddWithValue("@employeeid", SqlDbType.Int).Value = Convert.ToInt32(dtInsertRow.Rows[0]["employeeid"]);
cmd.Parameters.AddWithValue("@employeename", SqlDbType.VarChar).Value = Convert.ToString(dtInsertRow.Rows[0]["employeename"]);
cmd.Parameters.AddWithValue("@business", SqlDbType.VarChar).Value = Convert.ToString(dtInsertRow.Rows[0]["business"]);
cmd.Parameters.AddWithValue("@emailid", SqlDbType.VarChar).Value = Convert.ToString(dtInsertRow.Rows[0]["emailid"]);
cmd.Parameters.AddWithValue("@phoneno", SqlDbType.Int).Value = Convert.ToInt32(dtInsertRow.Rows[0]["phoneno"]);
cmd.ExecuteNonQuery();

}
catch
{

throw;

}

finally
{

con.Close();
con.Dispose();
}
int j = 0;
return j;

}

Author: Sagar Pardeshi             
Posted Date: January 29, 2010     Points: 5   

ur use store proc.

Author: Sagar Pardeshi             
Posted Date: January 29, 2010     Points: 5   

: archana

where u r from get information from front end

Author: archana             
Posted Date: January 29, 2010     Points: 5   

i cant use a stored procedure......the info from the front end is in the list object

Author: Sagar Pardeshi             
Posted Date: January 29, 2010     Points: 5   

simply u can write me ur problem i will send code snap

Author: Sagar Pardeshi             
Posted Date: January 29, 2010     Points: 5   

simply u can get info. from front end then store into database correct.whyu can use data table

Author: Sagar Pardeshi             
Posted Date: January 29, 2010     Points: 5   

send aspx page and .cs page my id sagapatemanon@gmail.com



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend