c# - How to shorten code using SQL Command -
here problem: want make code short, , friend of mine told me can use dal. don't know how use dal. tried search internet. doesn't give me simple solution. i'm newbie using dal
note: know select command short imagine extensive data.
aspx code
<div> <div> <asp:label id="lbl1" text="firstname" runat="server" /> </div> <div> <asp:textbox id="txtfname" runat="server" /> </div> <div> <div> <asp:label id="lbl2" text="middlename" runat="server" /> </div> <div> <asp:textbox id="txtmname" runat="server" /> </div> </div> <div> <div> <asp:label id="lbl3" text="lastname" runat="server" /> </div> <div> <asp:textbox id="txtlname" runat="server" /> </div> </div> <div> <div> <asp:label id="lbl4" text="birthday" runat="server" /> </div> <div> <asp:textbox id="txtbday" runat="server" /> </div> </div> <div> <div> <asp:label id="lbl5" text="address" runat="server" /> </div> <div> <asp:textbox id="txtadd" runat="server" /> </div> </div> </div>
aspx.cs code
protected void page_load(object sender, eventargs e) { selectcommand(); } private void selectcommand() { sqlcommand sqlselect = new sqlcommand(); sqlselect.connection = conn; sqlselect.commandtext = "select firstname = @firstname,middlename = @middlename,lastname = @lastname,birthdate = @birthdate, address = @address user"; sqlselect.commandtype = commandtype.text; sqlselect.parameters.addwithvalue("@firstname", txtfname.text); sqlselect.parameters.addwithvalue("@middlename", txtfname.text); sqlselect.parameters.addwithvalue("@lastname", txtfname.text); sqlselect.parameters.addwithvalue("@birthdate", txtbday.text); sqlselect.parameters.addwithvalue("@address", txtadd.text); conn.open(); sqlselect.executenonquery(); conn.close(); }
try separating purposes separate projects.
try reading through http://en.wikipedia.org/wiki/solid_(object-oriented_design). know wikipedia bland may give fundamental principles on oo design.
you can use linq sql or entity framework , remove lot of redundant code slower writing yourself.
Comments
Post a Comment