ASP.NET C#; Update Database from Comment Box

Volkof

Well-Known Member
Reaction score
31
I have this Comment Box, whereby the Doctor types in some words, press "Update" and the Comment Box will now show what the Doctor typed.
In addition, the Database should be updated with the Doctor's comment.
Problem is that the update did not occur. I typed in the Comment, clicked "Update", the text just reverted back to whatever was originally in the textbox, and the Database was never updated.
Any advise is appreciated. Thank you

Code:
<center>
<asp:SqlDataSource ID="viewPatSqlDataSource" runat="server"
        ConnectionString="<%$ ConnectionStrings:MISConnectionString %>"
        SelectCommand="SELECT p.Name, p.Gender, p.Age, m.RecordID, m.SickDescription FROM Patientinfo AS p INNER JOIN MedicalRecord AS m ON p.userID = m.userID WHERE (m.DepartmentID = @deptIDParam)">
        <SelectParameters>
            <asp:SessionParameter Name="deptIDParam" SessionField="DeptID" Type="Int16"
                DefaultValue="" />
        </SelectParameters>
    </asp:SqlDataSource>
 
    <asp:SqlDataSource ID="viewMedSqlDataSource" runat="server"
        ConnectionString="<%$ ConnectionStrings:MISConnectionString %>"       
        SelectCommand="SELECT RecordID, DepartmentID, SickDescription, DoctorComment, userID,Image
FROM MedicalRecord WHERE (RecordID = @recordIDParam)"
        UpdateCommand="UPDATE MedicalRecord SET DoctorComment = @commentParam WHERE (RecordID = @recordIDParam)">
        <SelectParameters>
            <asp:ControlParameter ControlID="viewPatGridView" Name="recordIDParam"
                PropertyName="SelectedValue" />
        </SelectParameters>
        <UpdateParameters>
            <asp:ControlParameter ControlID="viewPatDetailsView$commentTextBox" PropertyName="Text" Name="commentParam" Type="String" />     
            <asp:ControlParameter ControlID="viewPatGridView" PropertyName="SelectedValue" Name="recordIDParam" />
        </UpdateParameters>
 
    </asp:SqlDataSource>
 
    <asp:GridView ID="viewPatGridView" runat="server"
        AllowPaging="True"
        AllowSorting="True"
        AutoGenerateColumns="False"
        DataSourceID="viewPatSqlDataSource"
        EnableModelValidation="True"
        DataKeyNames="RecordID"
        Width="500px">
        <Columns>
            <asp:BoundField DataField="RecordID" HeaderText="RecordID"
                SortExpression="RecordID" InsertVisible="False" ReadOnly="True" />
            <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
            <asp:BoundField DataField="Gender" HeaderText="Gender"
                SortExpression="Gender" />
            <asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" />
            <asp:BoundField DataField="SickDescription" HeaderText="SickDescription"
                SortExpression="SickDescription" />
            <asp:CommandField ShowSelectButton="true" />
        </Columns>
    </asp:GridView>
    <br />
    <asp:DetailsView ID="viewPatDetailsView" runat="server" 
        AutoGenerateRows="False"
        DataSourceID="viewMedSqlDataSource"
        EnableModelValidation="True" 
        DefaultMode="Edit"
        DataKeyNames="RecordID"
        Width="500px" Height="10px">
        <Fields>
            <asp:BoundField DataField="RecordID" HeaderText="RecordID"
                InsertVisible="False" ReadOnly="True" SortExpression="RecordID" />
            <asp:TemplateField HeaderText="Sick Description" HeaderStyle-Width="150px"  SortExpression="SickDescription">
                <ItemTemplate>
                    <asp:Label ID="sickDescLabel" runat="server" Text='<%# Bind("SickDescription") %>'></asp:Label>
                </ItemTemplate>
 
<HeaderStyle Width="150px"></HeaderStyle>
            </asp:TemplateField>
 
            <asp:TemplateField HeaderText="Image" >                                   
                <ItemTemplate>                             
                    <asp:Image ID="Image1" runat="server" ImageUrl='<%# "HandlerRecord.ashx?ID=" + Eval("RecordID")%>'/>
                </ItemTemplate>
            </asp:TemplateField>
 
            <asp:TemplateField HeaderText="Comment" HeaderStyle-Width="150px"  SortExpression="DoctorComment">
                <EditItemTemplate>
                    <asp:TextBox ID="commentTextBox" TextMode="SingleLine" Width="200px" Height="100px" runat="server" Text='<%# Bind("DoctorComment") %>'></asp:TextBox>
                </EditItemTemplate>
                <HeaderStyle Width="150px"></HeaderStyle>
            </asp:TemplateField>
 
            <asp:TemplateField ShowHeader="False">
                <ItemTemplate>
                    <asp:Button ID="Button1" runat="server" CausesValidation="False"
                        CommandName="Edit" Text="Update" />
                </ItemTemplate>
 
                <EditItemTemplate>
                    <asp:Button ID="Button1" runat="server" CausesValidation="True"
                      OnClick ="update"  CommandName="Update" Text="Update" />
                </EditItemTemplate>
 
            </asp:TemplateField>
        </Fields>
    </asp:DetailsView>
</center>

P.S. This program is not written by me, but handed over to me to modify. So I am trying to understand it now in order to debug any errors.
 

rover2341

Is riding a roller coaster...Wee!
Reaction score
113
Edit* I noticed you said you were to edit or fix errors. not try a differnt solution. so my method below likey unhelpful. as its another way to go about it.


I can tell you how I handle it, but i go about it in a different way. If its not what you wanted, then ignore my answer. First off I am using mySQL so it could be a tad different but should be Very close if you were to do it my way.

1. I go to nuGet to get the mySQL dlls I need (built into vs).

2. First I add a Class called Connector, that i can get return no data back, get query data back as DataTable or List<List<string>>
Code:
    public class Connector
    {
        public static void SendQuery(MySqlCommand cmd)
        {
            cmd.Connection.Open();
            cmd.ExecuteReader();
        }
        public static DataTable QueryDb(MySqlCommand cmd)
        {
            cmd.Connection.Open();
 
            MySqlDataAdapter dataAdapter = new MySqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            dataAdapter.Fill(dt);
 
            return dt;
 
        }
        public static List<List<string>> QueryDBGetList(MySqlCommand cmd)
        {
            DataTable dt = QueryDb(cmd);
 
            List<List<string>> theRows = new List<List<string>>();
            foreach (DataRow dataRow in dt.Rows)
            {
                List<string> row = new List<string>();
                foreach (var v in dataRow.ItemArray)
                {
                    row.Add(v.ToString());
 
                    if (row.Last() == "")
                    {
                        row.Remove(row.Last());
                        row.Add("null");
                    }
                    row.Add(v.ToString());
                }
                theRows.Add(row);
            }
            return theRows;
        }
 
public static MySqlConnection SqlConnection()
        {
            string connstring = "";
            string dataBase = "";
            string dataSource = ";
            string userID = "";
            string password = "";
            connstring = "Data source=" + dataSource + ";Database=" + dataBase + ";UserID= " + userID + ";Password=" + password;
 
            MySqlConnection connection = new MySqlConnection(connstring);
 
            return connection;
        }
    }

3. Then In code, on the c# prehaps you use vb. I use this..
Code:
            MySqlCommand command = new MySqlCommand("select * from user", Connector.SqlConnection());
            var resultRows = Connector.QueryDB(command);


4. If I want it to have a site with ajax. I create a ashx page,
//I just pulled some code from one of my apis.
Code:
context.Response.ContentType = "text/plain";
            Connector connector = new Connector();
            JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
 
            MySqlCommand command = new MySqlCommand("select * from user", Connector.SqlConnection());
//When it returns as a list, you can serialize it to json and return it back as a javascrpit object :), if you use a datatable it becomes a mess)
            var resultRows = Connector.QueryDBGetList(command);
 
            context.Response.Write(jsonSerializer.Serialize(resultRows));

Then I could send the data though a html request using ajax and get the a return from the database. or if you dont need that you can just say on button click, run the code I had above
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    Actually I was just playing with having some kind of mention of the food forum and recipes on the main page to test and see if it would engage some of those people to post something. It is just weird to get so much traffic and no engagement
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top