Congratulations - C# Corner Q4, 2022 MVPs Announced
Why Join
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forum guidelines
Tri Setia
1.8k
376
14.9k
Populate Some Data into textbox ASP.NET Web Form
May 29 2021 11:30 AM
hi guys.. l'm try to popupate some data from database but always fail. I want if the btnAddCariAnggota click will show just nama_anggota not show all row in database. Any help could be appriaciate.
this is the tbl_anggota
CREATE
TABLE
[dbo].[tbl_anggota](
[id_anggota] [
varchar
](50)
NOT
NULL
,
[nama_anggota] [
varchar
](50)
NULL
,
[alamat] [
varchar
](350)
NULL
,
[no_telpon] [
varchar
](50)
NULL
,
[saldo] [
bigint
]
NULL
,
CONSTRAINT
[PK_tbl_anggota]
PRIMARY
KEY
CLUSTERED
(
[id_anggota]
ASC
)
WITH
(PAD_INDEX =
OFF
, STATISTICS_NORECOMPUTE =
OFF
, IGNORE_DUP_KEY =
OFF
, ALLOW_ROW_LOCKS =
ON
, ALLOW_PAGE_LOCKS =
ON
)
ON
[
PRIMARY
]
)
ON
[
PRIMARY
]
this is .aspx
<div
class
=
"col-md-6"
>
<div
class
=
"form-group"
>
<label
for
=
"id_anggota"
>
ID Anggota</label>
<div
class
=
"input-group"
>
<asp:TextBox ID=
"txtid_anggota"
runat=
"server"
CssClass=
"form-control"
placeholder=
"Enter ID Anggota"
></asp:TextBox>
<div
class
=
"input-group-append"
>
<asp:UpdatePanel ID=
"UpdatePanel1"
runat=
"server"
>
<ContentTemplate>
<asp:Button ID=
"btnAddCariAnggota"
CssClass=
"btn btn-warning"
runat=
"server"
Text=
"Cari Data Anggota"
OnClick=
"btnAddCariAnggota_Click"
/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
</div>
<div
class
=
"col-md-6"
>
<div
class
=
"form-group"
>
<label
for
=
"nama_anggota"
>
Nama Anggota</label>
<asp:TextBox ID=
"txtnama_anggota"
runat=
"server"
CssClass=
"form-control"
placeholder=
"Enter Nama Anggota"
ReadOnly=
"true"
></asp:TextBox>
</div>
</div>
this code bihind
protected
void
btnCariAnggota_Click(
object
sender, EventArgs e)
{
using
(SqlConnection con =
new
SqlConnection(koneksi))
{
using
(SqlCommand sqlcmd =
new
SqlCommand(
"Select * from tbl_anggota where id_anggota='"
+ txtid_anggota.Text.Trim() +
"'"
,con))
{
con.Open();
sqlcmd.Connection = con;
using
(SqlDataReader rdr = sqlcmd.ExecuteReader())
{
while
(rdr.Read())
{
txtnama_anggota.Text = rdr[
"nama_anggota"
].ToString();
}
}
con.Close();
}
}
}
Reply
Answers (
3
)
AutoValidate without PostBack
Protect .net core webapi from DDOS and DOS attack