This update query is not working. Can anyone help me with this one.
command.CommandText =
"UPDATE [Root_Cause_App_Rsn_Lookup] SET [Root_Cause_Grp_Cd]='" + RootCauseGroup + "', [Root_Cause_App_Rsn_Cd]='" + RootCauseAppReason + "', [Root_Cause_App_Rsn_Desc]='" + RootCauseAppReasonDescription + "' WHERE ([Root_Cause_Grp_Cd)= '" + RootCauseGroup +"')";
Joxin StanlyPosted Oct 1, 2013, 5:55 AM
"UPDATE [Root_Cause_App_Rsn_Lookup] SET [Root_Cause_App_Rsn_Desc]='" + RootCauseAppReasonDescription + "' WHERE ([Root_Cause_Grp_Cd]= '" + RootCauseGroup +"' and [Root_Cause_App_Rsn_Cd]= '" + RootCauseAppReason +"')";
Vignesh KumarPosted Oct 1, 2013, 7:19 AM
Vignesh KumarPosted Oct 1, 2013, 7:15 AM
Joxin StanlyPosted Oct 1, 2013, 7:12 AM
Please try running the Insert query (modify query with vales accordingly ) directly in sql server and see if it gets inserted ...
Vignesh KumarPosted Oct 1, 2013, 6:57 AM
protected void ResultGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
if (e.CommandName.Equals("AddNew"))
{
TextBox RootCauseGroup = (TextBox)GridView1.FooterRow.FindControl("txtRootCauseGroup");
TextBox RootCauseAppReason = (TextBox)GridView1.FooterRow.FindControl("txtRootCauseAppReason");
TextBox RootCauseAppReasonDescription = (TextBox)GridView1.FooterRow.FindControl("txtRootCauseAppReasonDescription");
RootCauseAppReasonDataBO.InsertRootCauseAppReasonValues(RootCauseGroup.Text, RootCauseAppReason.Text, RootCauseAppReasonDescription.Text);
FillVendorGrid();
}
}
catch (Exception exc)
{
Logger.LogError(exc, MethodBase.GetCurrentMethod().ToString());
UtilityMethods.RedirectToErrorPage(Constants.Message_ErrorProcessingRequest);
}
}
public static bool InsertRootCauseAppReasonValues(string RootCauseGroup, string RootCauseAppReason, string RootCauseAppReasonDescription)
{
string CS = ConfigurationManager.ConnectionStrings[Constants.EARSdConnectionString].ConnectionString;
using (SqlConnection connection = new SqlConnection(CS))
{
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = "INSERT INTO [Root_Cause_App_Rsn_Lookup]([Root_Cause_Grp_Cd],[Root_Cause_App_Rsn_Cd],[Root_Cause_App_Rsn_Desc]) Values('" + RootCauseGroup + "','" + RootCauseAppReason + "', '" + RootCauseAppReasonDescription + "')";
connection.Open();
command.ExecuteNonQuery();
}
return true;
}
Joxin StanlyPosted Oct 1, 2013, 6:54 AM
any error it is generating...
Vignesh KumarPosted Oct 1, 2013, 6:45 AM
All fine now. Finally this insert query is not working.
command.CommandText =
"INSERT INTO [Root_Cause_App_Rsn_Lookup]([Root_Cause_Grp_Cd],[Root_Cause_App_Rsn_Cd],[Root_Cause_App_Rsn_Desc]) Values('" + RootCauseGroup + "','" + RootCauseAppReason + "', '" + RootCauseAppReasonDescription + "')";Joxin StanlyPosted Oct 1, 2013, 6:32 AM
Vignesh KumarPosted Oct 1, 2013, 6:26 AM
That was fine. I AM STUCK WITH MY UPDATE QUERY NOW. I was able to add successfully but couldn't update. Can you pl shelp
command.CommandText =
"UPDATE [Root_Cause_Grp_Cd_Lookup] SET [Root_Cause_Grp_Cd] ='" + RootCauseGroup + "', [Root_Cause_Grp_Cd_Desc]='" + RootCauseGroupDescription + "' WHERE ([Root_Cause_Grp_Cd]='" + RootCauseGroup +"')";Joxin StanlyPosted Oct 1, 2013, 6:15 AM
command.CommandText =
"INSERT INTO [Root_Cause_Grp_Cd_Lookup]([Root_Cause_Grp_Cd],[Root_Cause_Grp_Cd_Desc]) Values ('" + RootCauseGroup + "','" + RootCauseGroupDescription + "')";Vignesh KumarPosted Oct 1, 2013, 6:09 AM
This is the error message I got when I debug.
Joxin StanlyPosted Oct 1, 2013, 6:04 AM
frankly i couldn't any issue in your insert query.
can you please check if it is throwing some error?
if yes, please paste the error here..
Vignesh KumarPosted Oct 1, 2013, 5:58 AM
Update is fine now. I am not able to insert data to the grid now. I am having problem with my insert query.
command.CommandText =
"INSERT INTO [Root_Cause_App_Rsn_Lookup]([Root_Cause_Grp_Cd],[Root_Cause_App_Rsn_Cd],[Root_Cause_App_Rsn_Desc]) Values('" + RootCauseGroup + "','" + RootCauseAppReason + "', '" + RootCauseAppReasonDescription + "')";
command.CommandText =
"INSERT INTO [Root_Cause_Grp_Cd_Lookup]([Root_Cause_Grp_Cd],[Root_Cause_Grp_Cd_Desc]) Values (" + RootCauseGroup + ",'" + RootCauseGroupDescription + "')";Vignesh KumarPosted Oct 1, 2013, 5:51 AM
Below is my table structure
CREATE
TABLE [dbo].[Root_Cause_App_Rsn_Lookup]([Root_Cause_Group_Cd] [char]
(3) NOT NULL,[Root_Cause_App_Rsn] [char]
(3) NOT NULL,[Root_Cause_App_Rsn_Desc] [varchar]
(50) NOT NULL,PRIMARY
KEY CLUSTERED(
[Root_Cause_Group_Cd]
ASC,[Root_Cause_App_Rsn]
ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY])
ON [PRIMARY]GO
SET
GO
ANSI_PADDING OFFJoxin StanlyPosted Oct 1, 2013, 5:51 AM
"UPDATE [Root_Cause_App_Rsn_Lookup] SET [Root_Cause_Grp_Cd]='" + RootCauseGroup + "', [Root_Cause_App_Rsn_Cd]='" + RootCauseAppReason + "', [Root_Cause_App_Rsn_Desc]='" + RootCauseAppReasonDescription + "' WHERE ([Root_Cause_Grp_Cd]= '" + RootCauseGroup +"' and [Root_Cause_App_Rsn_Cd]= '" + RootCauseAppReason +"')";
instead of above code, i think the better code is below (becos you dont need to update the columns specified in where clause)-:
"UPDATE [Root_Cause_App_Rsn_Lookup] SET [Root_Cause_App_Rsn_Desc]='" + RootCauseAppReasonDescription + "' WHERE ([Root_Cause_Grp_Cd]= '" + RootCauseGroup +"' and [Root_Cause_App_Rsn_Cd]= '" + RootCauseAppReason +"')";
Sanjeeb LenkaPosted Oct 1, 2013, 5:47 AM
plz share your database table structure which you want to update.
Vignesh KumarPosted Oct 1, 2013, 5:43 AM
I am trying to update Root_Cause_App_Rsn_Desc along with Root_Cause_Grp_Cd. The thing is I amnot sure of the where clause conditions, like we use 'where' and 'and' in the query condition whichi will have 2 columns (and these two are primary key columns)
Joxin StanlyPosted Oct 1, 2013, 5:38 AM
in the update scenario, are you looking for updating '[Root_Cause_App_Rsn_Desc]' only??
because i can see columns to update are also specified in where condition too..
am i missing something here?
Vignesh KumarPosted Oct 1, 2013, 5:29 AM
I need to add one more column after where clause Root_Cause_App_Rsn_Cd this one.
Where Root_Cause_Grp_Cd and Root_Cause_App_Rsn_Cd are primary keys. Can you help me with the query. I am using this to update rows in grid.
Also I do have problem with my isnert query too. I am not able to add datas to the grid.
command.CommandText =
"INSERT INTO [Root_Cause_App_Rsn_Lookup]([Root_Cause_Grp_Cd],[Root_Cause_App_Rsn_Cd],[Root_Cause_App_Rsn_Desc]) Values('" + RootCauseGroup + "','" + RootCauseAppReason + "', '" + RootCauseAppReasonDescription + "')";Joxin StanlyPosted Oct 1, 2013, 5:28 AM
either you can try Sanjeeb method or you can also try this
"UPDATE [Root_Cause_App_Rsn_Lookup] SET [Root_Cause_Grp_Cd]='" + RootCauseGroup + "', [Root_Cause_App_Rsn_Cd]='" + RootCauseAppReason + "', [Root_Cause_App_Rsn_Desc]='" + RootCauseAppReasonDescription + "' WHERE (Root_Cause_Grp_Cd= '" + RootCauseGroup +"')";
Sanjeeb LenkaPosted Oct 1, 2013, 5:22 AM
try this
command.CommandText ="UPDATE [Root_Cause_App_Rsn_Lookup] SET [Root_Cause_Grp_Cd]='" + RootCauseGroup + "', [Root_Cause_App_Rsn_Cd]='" + RootCauseAppReason + "', [Root_Cause_App_Rsn_Desc]='" + RootCauseAppReasonDescription + "' WHERE [Root_Cause_Grp_Cd]= '" + RootCauseGroup + "')";