Insertion and Updation Works Well with local but not on server

Posted by Neer under C# on 2/2/2012 | Points: 10 | Views : 744 | Status : [Member] | Replies : 2
Hi all.
I am trying to insert a data in a database

when i run locally, it works well. but on server its not giving error nor updating nor adding..

my date field is set to fetch system date. so i am not including that field in query , may it occure due to that??

What could b the solution for this??

-Neer


Responses

Posted by: Pradeepkumar417 on: 2/2/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

It is better to post the code what you have written and also what type of error you are getting in server.

Thanks & Regards,
Software Engineer,
Pradeep Kumar

Neer, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neer on: 2/2/2012 [Member] Starter | Points: 25

Up
0
Down
Sir I am Not Getting Any Error..

Here Is the code : (I am using 3 tire architecture so my insertion code in database.cs)

Insert page.cs
=============
Database db = new Database();
string str;

str = "insert into ABDatabase(MembershipID,CompanyName,BusinessCategory,ContactPerson,UserName,Password,Address,Area,City,PinCode,State,Phone,Mobile,Email,Website,Description,U_Admin) values (" + Convert.ToInt16(DropDownList2.SelectedItem.Value) + ",'" + txtName.Text + "','" + txtBusinessCategory1.Text + "','" + txtContactPerson.Text + "','" + txtUserName0.Text + "','" + txtPassword0.Text + "','" + txtAddress0.Text + "','" + DropDownList1.SelectedItem.Text + "','" + txtCity.Text + "','" + txtPinCode0.Text + "','" + txtState.Text + "','" + txtPhone0.Text + "','" + txtMobile0.Text + "','" + txtEmail0.Text + "','" + txtWebsite0.Text + "','" + txtDescription0.Text + "','" + Session["AdminUserName"].ToString() + "')";

db.ExecuteNonQuery1(str);
lblmsg0.Text = "Record inserted successfully";

--------------------------------------------------------------------------------------------------------------
Database.cs

public int ExecuteNonQuery1(string str)
{
String _ConnString = System.Configuration.ConfigurationManager.ConnectionStrings["dbConstr"].ConnectionString;

SqlConnection myConnection = new SqlConnection(_ConnString);
SqlCommand cmd = new SqlCommand(str, myConnection);
int result = 0;

try
{

myConnection.Open();
result =cmd.ExecuteNonQuery();

myConnection.Close();
}
catch (Exception ex)
{
result = -1;
try
{
if (myConnection.State == ConnectionState.Open)
{
myConnection.Close();
}
}
catch (Exception ex2)
{
if (myConnection.State == ConnectionState.Open)
myConnection.Close();
}

}

return result;


}

-Neer

Neer, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response