Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > .NET Framework > Forum > อยากทราบวิธีนำข้อมูลใน textbox ไปใส่ในฐานข้อมูลครับ เกี่ยวกับออฟเจค


 

[.NET] อยากทราบวิธีนำข้อมูลใน textbox ไปใส่ในฐานข้อมูลครับ เกี่ยวกับออฟเจค

 
Topic : 060042



โพสกระทู้ ( 25 )
บทความ ( 0 )



สถานะออฟไลน์



Code (C#)
001.<%@ Import Namespace="System.Data"%>
002.<%@ Import Namespace="System.Data.SqlClient"%>
003.<%@ Page Language="C#" Debug="true" EnableEventValidation="true" %>
004.<script runat="server">
005.     
006.    SqlConnection objConn;
007.    SqlCommand objCmd;
008.    String strSQL;
009. 
010.    public void Page_Load(object sender, EventArgs e)
011.    {
012.         
013.            String strConnString;
014.            strConnString = "Server=localhost;UID=sa;PASSWORD=;database=cartoon;Max Pool Size=400;Connect Timeout=6000;";
015.            objConn = new SqlConnection(strConnString);
016.            objConn.Open();
017.            if (!Page.IsPostBack)
018.            {
019.                BindData();
020.            }
021.         
022.    }
023. 
024.    void BindData()
025.    {
026.        String strSQL;
027.        strSQL = "select top (1)CusID from Customer order by CusID desc";
028.         
029.        SqlDataReader dtReader;
030.        objCmd = new SqlCommand(strSQL, objConn);
031.        dtReader = objCmd.ExecuteReader();
032.         
033.         
034.        dtReader.Close();
035.        dtReader = null;
036.    }
037. 
038.     
039. 
040.    protected void Button2_Click(object sender, EventArgs e)
041.    {
042.         //*** Pub ***//
043.         TextBox txtTextBox1 = this.TextBox1.Text;
044.         //*** SetProductID ***//
045.         TextBox txtTextBox2 = this.TextBox2.Text;
046.        //*** SetProductName ***//
047.         TextBox txtTextBox3 = this.TextBox3.Text;
048.        //*** Detail ***//
049.         TextBox txtTextBox4 = this.TextBox4.Text;
050.        //*** Author ***//
051.         TextBox txtTextBox5 = this.TextBox5.Text;
052. 
053. 
054.         strSQL = "update Customer set Name='" + txtTextBox1.Text + "',SurName='" + txtTextBox2.Text + "',Address ='" + txtTextBox3.Text + "',Email='" + txtTextBox4.Text + "',Phone='" + txtTextBox5.Text + "' where CusID = (select top(1)CusID from Customer order by CusID desc)";
055.        objCmd = new SqlCommand(strSQL, objConn);
056.        objCmd.ExecuteNonQuery();
057.        //Response.Write("á¡éä¢" + txtSetProductID.Text + " àÃÕºÃéÍÂáÅéÇ");
058.    }
059.</script>
060. 
061.<html>
062.<head id="Head1" runat="server">
063.<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
064.<title>Cartoon2ndHand</title>
065.<style type="text/css">
066. 
067.body {
068.    background-image: url(images/bg.gif);
069.    background-repeat: repeat;
070.}
071.a {
072.    font-size: 10px;
073.}
074.    .style9
075.    {
076.        height: 31px;
077.    }
078.    .style10
079.    {
080.        height: 26px;
081.    }
082.-->
083.</style></head>
084.<body><form id="form1" runat="server">
085. 
086.<table width="961" height="1281" border="0" align="center">
087.  <tr>
088.    <td width="1024" height="1277" valign="top"><table width="955" height="1275" border="0">
089.      <tr>
090.        <td width="949" height="132"><div align="center"><img src="images/header edit.jpg" width="934" height="126" /></div></td>
091.      </tr>
092.      <tr>
093.        <td class="style10"><table height="35" border="0" align="center"
094.                style="width: 949px">
095.          <tr align="center">
096.            <td width="173" class="style9"><a href="default.aspx"><img src="images/Tab home.jpg" width="150" height="30" border="0" /></a></td>
097.            <td width="150" class="style9"><a href="page1.aspx"><img src="images/Tab product light.jpg" width="150" height="30" border="0"></a></td>
098.            <td width="150" class="style9"><a href="page2.aspx"><img src="images/Tab Buy the book..jpg" width="150" height="30" border="0"></a></td>
099.            <td width="150" class="style9"><a href="page3.aspx"><img src="images/Tab How to order.jpg" width="150" height="30" border="0"></a></td>
100.            <td width="150" class="style9"><a href="page4.aspx"><img src="images/Tab Contact us.jpg" width="150" height="30" border="0"></a></td>
101.            <td width="222" class="style9"><asp:HyperLink id="hplLogout" NavigateURL="Logout.aspx" runat="server"><img src="images/logout.jpg" width="150" height="30"></asp:HyperLink></td>
102.          </tr>
103.        </table></td>
104.      </tr>
105.      <tr>
106.        <td height="1097" valign="top"><table width="949" height="1095" border="0">
107.          <tr>
108.            <td width="180" height="1091" valign="top"><table width="180" height="500" border="1" align="left" cellpadding="0" cellspacing="0">
109.              <tr>
110.                <td width="204">
111.                                  &nbsp;</td>
112.              </tr>
113.              <tr>
114.                <td>&nbsp;</td>
115.              </tr>
116.              <tr>
117.                <td>&nbsp;</td>
118.              </tr>
119.              <tr>
120.                <td>&nbsp;</td>
121.              </tr>
122.              <tr>
123.                <td>&nbsp;</td>
124.              </tr>
125.              <tr>
126.                <td>&nbsp;</td>
127.              </tr>
128.              <tr>
129.                <td>&nbsp;</td>
130.              </tr>
131.               
132.            </table></td>
133.            <td width="759" valign="top"><p><img src="images/managepurchase.jpg" width="700" height="35"><br />
134.              <br />
135.                     
136.                             &nbsp;&nbsp;&nbsp;&nbsp;     
137.                              
138.                &nbsp;
139.                <br />ª×èÍ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
140.                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
141.                <asp:Label ID="Label1" runat="server" Text=" "></asp:Label>
142.                <br />
143.                <br />
144.                ¹ÒÁÊ¡ØÅ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                 <asp:TextBox ID=" " runat="server" Width="192px"></asp:TextBox>
145.                <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
146.                <br />
147.                <br />
148.                ·ÕèÍÂÙè&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                 <asp:TextBox ID=" " runat="server" Height="58px" Width="319px"></asp:TextBox>
149.                <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
150.                <br />
151.                <br />
152.                E-Mail&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                 <asp:TextBox ID=" " runat="server"></asp:TextBox>
153.                <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
154.                <br />
155.                <br />
156.                àºÍÃìâ·ÃÈѾ·ì                 <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
157.                                        <asp:Label ID="Label5" runat="server" Text=" "></asp:Label>
158.                                        </p>
159.                                        <p>&nbsp;</p>
160.                                        <p>&nbsp;<br />
161.                     
162. 
163.                     
164.                <br />
165.                <asp:Button ID="Button2" runat="server" Text="Â×¹Âѹ¡ÒÃÊÑ觫×éÍ"
166.                    PostBackUrl="~/page5-2-3.aspx" onclick="Button2_Click" />
167.                                        </p>
168.                  </td>
169.          </tr>
170.        </table></td>
171.      </tr>
172.    </table></td>
173.  </tr>
174.</table>
175.</form>
176.</body>
177.</html>


คิดว่าเป็นแถวๆบันทัดที่ 40 น่ะครับ เกี่ยวกับ object ของ textbox



Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), C#



ประวัติการแก้ไข
2011-05-11 13:21:23
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-05-11 13:15:09 By : ekarit View : 1038 Reply : 4
 

 

No. 1



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

อันที่จริงคุณก็เรียก this.TextBox1.Text ได้เลยน่ะครับ ไม่ต้องประกาศ new ขึ้นมาอีกครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-05-11 14:08:07 By : webmaster
 

 

No. 2



โพสกระทู้ ( 25 )
บทความ ( 0 )



สถานะออฟไลน์


แก้เป็น

strSQL = "update Customer set Name='" +This.TextBox1.Text + "',SurName='" + This.TextBox2.Text + "',Address ='" + This.TextBox3.Text + "',Email='" + This.TextBox4.Text + "',Phone='" + This.TextBox5.Text + "' where CusID = (select top(1)CusID from Customer order by CusID desc)";

ก็ยังใช้ไม่ได้ครับ Error Objeck referrence not set to an instance of object
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-05-11 14:24:39 By : ekarit
 

 

No. 3



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

this ตัวพิมพ์เล็กครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-05-11 14:46:30 By : webmaster
 

 

No. 4

Guest


ได้แล้วครับ ขอบคุณครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-05-11 16:17:36 By : aekarits
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : อยากทราบวิธีนำข้อมูลใน textbox ไปใส่ในฐานข้อมูลครับ เกี่ยวกับออฟเจค
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่