I have a page which allows the user to display all records, or search for a particular one. There is an edit column in the datagrid. There is a method for display all records; ReadRecords, and one for search; ReadRecord. I was wondering how I write the event handler so the edit function can be carried out correctly for both datadisplays. At the minute I can only get it working for one of the methods at a time eg. below for the ReadRecord: private void DrugInformationDataGrid_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { DrugInformationDataGrid.EditItemIndex = e.Item.ItemIndex; ReadRecord(); } I need it to work with ReadRecords also. Appreciate any help Rory
mccarthy111
Posts
-
Edit in Datagrid -
Datagrid EditI have a page which allows the user to display all records, or search for a particular one. There is an edit column in the datagrid. There is a method for display all records; ReadRecords, and one for search; ReadRecord. I was wondering how I write the event handler so the edit function can be carried out correctly for both datadisplays. At the minute I can only get it working for one of the methods at a time eg. below for the ReadRecord: private void DrugInformationDataGrid_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { DrugInformationDataGrid.EditItemIndex = e.Item.ItemIndex; ReadRecord(); } I need it to work with ReadRecords also. Appreciate any help? Rory
-
Search boxI have tried to parameterize the query to see if that would work. again the Drug No search works but the DrugName search returns the following error: Input string was not in a correct format. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.FormatException: Input string was not in a correct format. Here is my updated code: string StrUserSearchValue = TextBox1.Text; OleDbCommand cmd = new OleDbCommand("Select * FROM DRUG_INFORMATION WHERE DRUG_INFORMATION.DrugNo = ? OR DRUG_INFORMATION.DrugName = ?", conn); cmd.Parameters.Add(new OleDbParameter("@DrugNo", OleDbType.Integer)).Value = StrUserSearchValue; cmd.Parameters.Add(new OleDbParameter("@DrugName", OleDbType.VarChar)).Value = StrUserSearchValue; reader = cmd.ExecuteReader(); Any ideas? Thanks Rory
-
Search boxThe thing is i have implemented many other functions which require the DrugNo set as autonumber as datatype. The code you gave initially searched using the DrugNo alright retireving the relevant row, it was the DrugName which wasn't retrieving any data. If the above method is possible using DrugNo as autonumber, how would I add a combobox with these values and how would the sql look. Or else is it possible that something could be changed in the first sql you provided to get the drugname search working as well. Thanks alot for your time. Much appreciated. Rory
-
Search boxThanks for that. Your advice helped me sort out a few other problems too. The sql you provided enables the number search to work okay, but the search for the drugname comes up with the following error: No value given for one or more required parameters. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters. Source Error: Line 75: OleDbCommand cmd = Line 76: new OleDbCommand("Select * FROM DRUG_INFORMATION WHERE DRUG_INFORMATION.DrugNo =" + StrUserSearchValue + " OR DRUG_INFORMATION.DrugName = '" + StrUserSearchValue + "'", conn); Line 77: reader = cmd.ExecuteReader(); Line 78: Line 79: DrugSearchDataGrid.DataSource = reader; Can you figure it out? Cheers again
-
AuthenticationMy passwordformat="clear" What value would I replace "clear" with to make the password concealed i.e.:*******, to the user?
-
Search boxCheers, How would I write this line without the if statment? When I take the if out I get errors. I tried taking out the whole of: if (!IsPostBack) When this is done I get the following error: No value given for one or more required parameters. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters. Source Error: Line 75: OleDbCommand cmd = Line 76: new OleDbCommand("SELECT * FROM DRUG_INFORMATION WHERE DrugNo.DRUG_INFORMATION = StrUserSearchValue OR DrugName.DRUG_INFORMATION = StrUserSearchValue", conn); Line 77: reader = cmd.ExecuteReader(); Line 78: Line 79: DrugSearchDataGrid.DataSource = reader; Source File: c:\inetpub\wwwroot\gp\drugsearch.aspx.cs Line: 77 Stack Trace: [OleDbException (0x80040e10): No value given for one or more required parameters.] System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +174 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92 System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +65 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +112 System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) +69 System.Data.OleDb.OleDbCommand.ExecuteReader() +7 GP.DrugSearch.ReadRecords() in c:\inetpub\wwwroot\gp\drugsearch.aspx.cs:77 GP.DrugSearch.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\gp\drugsearch.aspx.cs:58 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain() +1277
-
Search boxI have made a simple page with a text box, a button and a datagrid. The user inputs the drug number or name into the box and clicks submit, and I want the database results to be displayed on the datagrid but when I run it nothing happens. I'm new to using textboxes for searching. I want the button event handler to use the read records method and then display the results on the datagrid. Below is my code: private void Button1_Click(object sender, System.EventArgs e) { if (!IsPostBack) ReadRecords(); } private void ReadRecords() { OleDbConnection conn = null; OleDbDataReader reader = null; try { conn = new OleDbConnection( @"Provider=Microsoft.Jet.OLEDB.4.0; " + @"Data Source=" + Server.MapPath("GeneralPractice/GeneralPractice.mdb")); conn.Open(); string StrUserSearchValue = TextBox1.Text; OleDbCommand cmd = new OleDbCommand("Select * FROM DRUG_INFORMATION WHERE DrugNo.DRUG_INFORMATION = StrUserSearchValue OR DrugName.DRUG_INFORMATION = StrUserSearchValue", conn); reader = cmd.ExecuteReader(); DrugSearchDataGrid.DataSource = reader; DrugSearchDataGrid.DataKeyField = "DrugNo"; DrugSearchDataGrid.DataBind(); } // catch (Exception e) // { // Response.Write(e.Message); // Response.End(); // } finally { if (reader != null) reader.Close(); if (conn != null) conn.Close(); } } Thanks in advance for any help Rory
-
Authenticationthanks alot poeple. Just had to remove that first tag!:)
-
Datagrid Row UpdateThe datagrid still disappears when I run the command. I have a read records method which before trying the code I gave, I was trying to call in the update method, but when I called it it took two attempts of the update button click for the grid to be updated. Below is that method, if it can be used? private void ReadRecords() { OleDbConnection conn = null; OleDbDataReader reader = null; try { conn = new OleDbConnection( @"Provider=Microsoft.Jet.OLEDB.4.0; " + @"Data Source=" + Server.MapPath("GeneralPractice/GeneralPractice.mdb")); conn.Open(); OleDbCommand cmd = new OleDbCommand("Select * FROM DIAGNOSIS", conn); reader = cmd.ExecuteReader(); DiagnosisListDataGrid.DataSource = reader; DiagnosisListDataGrid.DataKeyField = "DiagnosisNo"; DiagnosisListDataGrid.DataBind(); } // catch (Exception e) // { // Response.Write(e.Message); // Response.End(); // } finally { if (reader != null) reader.Close(); if (conn != null) conn.Close(); } } Thanks Rory
-
Datagrid Row UpdateThe datagrid still disappears when I run the command. I have a read records method which before I was trying to call, but when I called it it took two attempts two attempt of the update button click for the grid to be updated. Below is that method, if it can be used? private void ReadRecords() { OleDbConnection conn = null; OleDbDataReader reader = null; try { conn = new OleDbConnection( @"Provider=Microsoft.Jet.OLEDB.4.0; " + @"Data Source=" + Server.MapPath("GeneralPractice/GeneralPractice.mdb")); conn.Open(); OleDbCommand cmd = new OleDbCommand("Select * FROM DIAGNOSIS", conn); reader = cmd.ExecuteReader(); DiagnosisListDataGrid.DataSource = reader; DiagnosisListDataGrid.DataKeyField = "DiagnosisNo"; DiagnosisListDataGrid.DataBind(); } // catch (Exception e) // { // Response.Write(e.Message); // Response.End(); // } finally { if (reader != null) reader.Close(); if (conn != null) conn.Close(); } } Thanks
-
AuthenticationI have made a login page and configured the web.config file adding the appropriate authentication and authorization code. BUT I keep getting errors with this: Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. Parser Error Message: The 'authentication' start tag on line '46' doesn't match the end tag of 'forms' in file 'file:///c:/inetpub/wwwroot/GP/web.config'. Line 51, position 5. Source Error: Line 49: Line 50: Line 51: Line 52: Line 53: I don't understand as I got this from one source and checked it with another and it is the same. Whats wrong with this anyone??
-
Datagrid Row UpdateAfter update I entered this statement to bind the data: DiagnosisListDataGrid.DataBind();
-
Datagrid Row UpdateWhen I enter the bind statement it doesn't help the problem?
-
Datagrid Row UpdateWould you be able to tell me how I can set the datasource property of my datagrid? Thanks
-
Datagrid Row UpdateI have made a function to update data edited in a datagrid row. Here is the code: private void DiagnosisListDataGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { int DiagnosisNo = (int) DiagnosisListDataGrid.DataKeys[(int) e.Item.ItemIndex]; string nino = ((TextBox)e.Item.Cells[3].Controls[0]).Text; string datetime = ((TextBox)e.Item.Cells[4].Controls[0]).Text; string details = ((TextBox)e.Item.Cells[5].Controls[0]).Text; string currentstatus = ((TextBox)e.Item.Cells[6].Controls[0]).Text; string sql = "UPDATE DIAGNOSIS SET NINo=?, [DateTime]=?, Details=?, currentStatus=? WHERE DiagnosisNo= ?"; DiagnosisListDataGrid.EditItemIndex = -1; OleDbConnection conn = new OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("GeneralPractice/GeneralPractice.mdb")); OleDbCommand cmd = new OleDbCommand(sql, conn); cmd.Parameters.Add("NINo", nino); cmd.Parameters.Add("DateTime", datetime); cmd.Parameters.Add("Details", details); cmd.Parameters.Add("CurrentStatus", currentstatus); cmd.Parameters.Add("DiagnosisNo",DiagnosisNo); //ReadRecords(); conn.Open(); try { cmd.ExecuteNonQuery(); } finally { DiagnosisListDataGrid.DataBind(); if (conn != null) conn.Close(); } } The problem is that when the update button is cicked the datagrid disappears from the page. If it is loaded up again the info has been updated. Anyone know what am i'm missing out here? Rory
-
Datagrid Search Box functionoh yeah it also uses access as the database. Cheers
-
Datagrid Search Box functionI have datagrids with edit, add and delete functions. I am using asp.net c# in visual studio and need to make a search box facility whereby matching results are returned in the datagrid. Would appreciate it if anyone could give me some advice on going around this. Helpful websites, tutorials etc would also be great. Thank You Rory
-
Specified cast is not valid - Update Datagrid errorI have implemented the code in a slightly different way shown below: private void DiagnosisListDataGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { int DiagnosisNo = (int) DiagnosisListDataGrid.DataKeys[(int) e.Item.ItemIndex]; string nino = ((TextBox)e.Item.Cells[3].Controls[0]).Text; string datetime = ((TextBox)e.Item.Cells[4].Controls[0]).Text; string details = ((TextBox)e.Item.Cells[5].Controls[0]).Text; string currentstatus = ((TextBox)e.Item.Cells[6].Controls[0]).Text; string sql = "UPDATE DIAGNOSIS SET NINo=@nino, [DateTime]=@datetime, Details=@details, CurrentStatus= " + " @currentstatus WHERE DiagnosisNo= @DiagnosisNo"; OleDbCommand cmd = new OleDbCommand(sql); cmd.Parameters.Add("@nino", nino); cmd.Parameters.Add("@datetime", datetime); cmd.Parameters.Add("@details", details); cmd.Parameters.Add("@currentstatus", currentstatus); ExecuteNonQuery(sql); DiagnosisListDataGrid.EditItemIndex = -1; ReadRecords(); } This has got rid of all the build errors but now when I attempt to use the update function in the browser, the following error is returned: Server Error in '/GP' Application. -------------------------------------------------------------------------------- No value given for one or more required parameters. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters. Source Error: Line 148: OleDbCommand cmd = Line 149: new OleDbCommand(sql, conn); Line 150: cmd.ExecuteNonQuery(); Line 151: } Line 152: // catch (Exception e) Source File: c:\inetpub\wwwroot\gp\diagnosislist.aspx.cs Line: 150 Stack Trace: [OleDbException (0x80040e10): No value given for one or more required parameters.] System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +174 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92 System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +65 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +112 System
-
Specified cast is not valid - Update Datagrid errorHow would I go about setting the connection of the command in the execute nonquery method, shown in my first thread? I did the rest of what you said, and the errors are still appearing. Wish I could get this working, severely running out of time! Cheers for helping. Rory