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,027

HOME > .NET Framework > Forum > ดึงข้อมูลรายละเอียด GridView ในฐาน้อมูลมายัง TextBox ได้แล้ว update ผ่าน textbox ทำยังไงครับ



 

ดึงข้อมูลรายละเอียด GridView ในฐาน้อมูลมายัง TextBox ได้แล้ว update ผ่าน textbox ทำยังไงครับ

 



Topic : 088565



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



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




ตอนนี้สามาถดึงข้อมูลลายละเอียดGridView ในฐาน้อมูลมายัง TextBox ได้แล้วแต่ทำไมไม่สามารถ updateผ่านTextbox ได้ครับทั้งที่เขียน code update แล้วครับพอดีมือใหม่ครับ

updatetextbox



Tag : ASP.NET Ms SQL Server 2012, Web (ASP.NET), VS 2012 (.NET 4.x)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-12-26 13:48:52 By : clarity View : 1407 Reply : 5
 

 

No. 1



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



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


หลังจาก update คุณก็ไป select มาใหม่สิครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-26 17:33:02 By : kanchen
 


 

No. 2



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

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

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



Go to : (C#) ASP.NET SQL Server Edit/Update Record
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-27 10:01:14 By : mr.win
 

 

No. 3

Guest


Code
update "name table"
set "name field" = " textbox1.text "
where "name field" = " ค่าเดิมที่ต้องการเปลี่ยน หรือ ค่าที่รับจาก textbox2.text "

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-27 11:55:04 By : yo
 


 

No. 4



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



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


พอดีเขียน code แล้วขึ้น Build: 1 succeeded or up-to-date, 0 failed, 0 skipped แต่ยังไม่สามารถ update ได้ครับ
ช่วยชี้แนะด้วยครับว่าต้องเพิ่มตรงไหนหรือต้องแก้ไขส่วนบรรทัดที่เท่าไหร่ครับขอบคุณมากครับ


if(!Page.IsPostBack)
        {

        ViewData();

        }

        }
    void ViewData()
    {

        DataTable dt = new DataTable();
        strconn = "SELECT * FROM customer WHERE no = '" + Request.QueryString["no"]
        + "' ";
        da = new SqlDataAdapter(strconn, conn);
        da.Fill(dt);

        if (dt.Rows.Count > 0)
        {
            this.TextBox1.Text = (string)dt.Rows[0]["no"];
            this.TextBox2.Text = (string)dt.Rows[0]["fname"];
            this.TextBox3.Text = (string)dt.Rows[0]["lname"];
            this.TextBox4.Text = (string)dt.Rows[0]["email"];
            this.TextBox5.Text = (string)dt.Rows[0]["pwd"];

        }

    }

    
    protected void Button1_Click(object sender, EventArgs e)
    {
        strconn  = "insert into customer(no,fname,lname ,email,pwd)";

        strconn += "values(' " + TextBox1.Text + " ', ";
        strconn +=" '" +TextBox2.Text+" '  ,";
        strconn += " '" + TextBox3.Text + " ',";
        strconn += " '" + TextBox4.Text + " ',";
        strconn += " '" + TextBox5.Text + " ')";
        comm =  new SqlCommand(strconn,conn);
        dr = comm.ExecuteReader();
        
        Response.Redirect("http://localhost/test/selectlist.aspx");
      
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        GridView tmpdrg = (GridView)(sender);
        int irow = -1;

        if (!Page.IsPostBack != null)
        {
            irow = (Convert.ToInt32(e.CommandArgument));
        }
        if (tmpdrg.Rows[irow].Cells[1].Text != null)
        {

            TextBox1.Text = (tmpdrg.Rows[irow].Cells[0].Text);
            TextBox2.Text = (tmpdrg.Rows[irow].Cells[1].Text);
            TextBox3.Text = (tmpdrg.Rows[irow].Cells[2].Text);
            TextBox4.Text = (tmpdrg.Rows[irow].Cells[3].Text);
            TextBox5.Text = (tmpdrg.Rows[irow].Cells[4].Text);
        }
    }



    protected void Button2_Click(object sender, EventArgs e)
    {
                strconn = "UPDATE customer SET " +
                " no = '"+ this.TextBox1.Text +"' " +
                " ,fname = '"+ this.TextBox2.Text +"' " +
                " ,lname = '"+ this.TextBox3.Text +"' " +
                " ,email = '"+ this.TextBox4.Text +"' " +
                " ,pwd = '"+ this.TextBox5.Text +"' " +
               
                " WHERE no = '" + Request.QueryString["no"] + "' ";

                comm = new SqlCommand();
                comm.Connection = conn;
                comm.CommandText = strconn;
                comm .CommandType = CommandType.Text;
               
              

                try
                {

                comm.ExecuteNonQuery();
                this.lblStatus.Text = "Record Updated";
                this.lblStatus.Visible = true;

                } catch 
                   
                    ( Exception ex)
                {

                this.lblStatus.Text = "Record can not update";
              }
           }
                void Page_UnLoad()
             {
                conn.Close();
                conn = null;
           }
    }

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-28 13:46:13 By : clarity
 


 

No. 5



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



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


updatetextbox

พอดีดึงข้อมูลจาก Gridview กับ Drop Downlist มาแสดงที่ TextBox ได้แล้วครับแต่ทำไมยังไม่สามารถ Update ได้ครับ
code ไม่ทราบว่าผิดพลาดตรงไหนครับขอคำชี้แนะด้วยครับ
********************************************************************************************************************
strsql = "Data Source=NOTEBOOK;Initial Catalog=windows;
conn = new SqlConnection(strsql);
conn.Open();
if (!IsPostBack)
{
BindData();
}
}
void BindData()
{

dt = new DataTable();
strsql = "SELECT * FROM academic WHERE sequenceID = '" + Request.QueryString["sequenceID"] + "' ";
da = new SqlDataAdapter(strsql, conn);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
TextBox1.Text = (string)dt.Rows[0]["sequenceID"];
txtbooklist.Text = (string)dt.Rows[0]["name"];
txtclass.Text = (string)dt.Rows[0]["txtidcourse"];
txtisbn.Text = (string)dt.Rows[0]["isbn"];
txtemail.Text = (string)dt.Rows[0]["email"];
txtinstructure.Text = (string)dt.Rows[0]["instructure"];
}

}


protected void grvacademiclist_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridView tmpdrg = (GridView)(sender);
int irow= -1;

if(e.CommandArgument != null)
{

irow = (Convert.ToInt32(e.CommandArgument));
}

if (tmpdrg.Rows[irow].Cells[1].Text != null)
{

TextBox1.Text = (tmpdrg.Rows[irow].Cells[0].Text);
txtbooklist.Text = (tmpdrg.Rows[irow].Cells[1].Text);
txtclass.Text = (tmpdrg.Rows[irow].Cells[2].Text);
txtisbn.Text = (tmpdrg.Rows[irow].Cells[3].Text);
txtemail.Text = (tmpdrg.Rows[irow].Cells[4].Text);
txtinstructure.Text = (tmpdrg.Rows[irow].Cells[5].Text);


}
}
protected void btnadd_Click(object sender, EventArgs e)
{
strsql = "insert into academic ";

strsql += "values('"+ txtbooklist.Text + "',";
strsql += "'" + txtclass.Text + "',";
strsql += "'" + txtisbn.Text + "',";
strsql += "'" + txtemail.Text + "',";
strsql += "'" + txtinstructure.Text + "')";

comm = new SqlCommand(strsql, conn);
dr = comm.ExecuteReader();
dr.Close();
conn.Close();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

strsql = "SELECT * FROM academic WHERE sequenceID = '" + DropDownList1.SelectedItem.Text + "' ";
da = new SqlDataAdapter(strsql, conn);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
TextBox1.Text = (string)dt.Rows[0]["sequenceID"].ToString();
txtbooklist.Text = (string)dt.Rows[0]["name"].ToString();
txtclass.Text = (string)dt.Rows[0]["txtidcourse"].ToString();
txtisbn.Text = (string)dt.Rows[0]["isbn"].ToString();
txtemail.Text = (string)dt.Rows[0]["email"].ToString();
txtinstructure.Text = (string)dt.Rows[0]["instructure"].ToString();
}
}
protected void btnedit_Click(object sender, EventArgs e)
{

strsql = "UPDATE academic SET " +
" sequenceID = '" + this.TextBox1.Text + "' " +
" , name= '" + this.txtbooklist.Text + "' " +
" , txtidcourse= '" + this.txtclass.Text + "' " +
" , isbn= '" + this.txtisbn.Text + "' " +
" ,email = '" + this. txtemail.Text + "' " +
" , instructure= '" + this.txtinstructure.Text + "' " +
" WHERE sequenceID = '" + Request.QueryString["sequenceID"] + "' ";


SqlCommand comm = new SqlCommand();

try
{
conn.ConnectionString = strsql;

if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Open();

comm.CommandType = CommandType.Text;
comm.CommandText = strsql;
comm.Connection =conn;
}
catch (Exception ex)
{
Label1.Text= ("Record can not update");
}
finally
{
conn.Close();
}


}
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-01-07 14:08:06 By : clarity
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ดึงข้อมูลรายละเอียด GridView ในฐาน้อมูลมายัง TextBox ได้แล้ว update ผ่าน 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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

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