Displaying field to textbox
-
11 Juli 2012 1:20
I have 2 tables which are contain ID field, on the second table I want to add a record based on ID from table 1 so I provide users to input on a text box for ID and the field Subject will appear on another the text box, here are my code that throws an exception for declaring scalar variable @ID
private void textBox6_KeyDown(object sender, KeyEventArgs e)
{
if (radioButton2.Checked)
{
if (e.KeyCode == Keys.Enter)
{
try
{
SqlCommand perintahsql = new SqlCommand("select Subject from jadwalkuliah where ID = @ID", koneksi);
SqlParameter parameter = new SqlParameter();
parameter.ParameterName = "@ID";
parameter.SqlDbType = SqlDbType.Int;
parameter.Direction = ParameterDirection.Input;
parameter.Value = textBox6.ToString();
koneksi.Open();
SqlDataReader bacadata = perintahsql.ExecuteReader();
if (bacadata.HasRows)
{
while (bacadata.Read())
{
textBox2.Text = bacadata["Subject"].ToString();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex + "ex");
}
koneksi.Close();
}
}
}
- Diedit oleh Raditya Kurnianto 11 Juli 2012 1:52
- Diedit oleh Raditya Kurnianto 11 Juli 2012 1:53
Semua Balasan
-
11 Juli 2012 13:07
salam hangat,
bisa diperjelas maksd anda
kind regard
-
13 Juli 2012 0:04baik, jadi saya memiliki 2 tabel, tabel 1 memiliki field ID, Subject, Day, Time, Location dgn ID sebagai primary key dan auto increment. Pada tabel 2 pun fieldnya hampir sama. Nah ditabel kedua saya ingin menambahkan record dengan cara user memasukan ID record yg sudah ada pada tabel 1 pada text box, kemudian user menekan enter dan muncullah value dari field Subject di text box yang lain,begitulah skenarionya.
-
15 Juli 2012 8:51
Salam hangat,
Hai, raditya kurnianto maaf lama relpy post anda.
baik untuk permasalahan anda coba sebainya anda gunakan passing parameter sebagai call stored prosedurnya. coba check disini ya untuk guidenya
http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/e9d17dcf-55ce-4a67-9a56-f5955638e51e/
http://msdn.microsoft.com/en-us/library/0f66670z%28v=vs.71%29.aspxjadi, kurang lebih 'parameter.ParameterName = "@ID";'
yg anda passing utk call stored prosedurnya, karena parameter ini yg ingin anda bagi value nya untuk ke 2 tabel.semoga bisa membantu,
- Disarankan sebagai Jawaban oleh r aditya gumay 15 Juli 2012 8:52
- Ditandai sebagai Jawaban oleh Agnes SannieMicrosoft Contingent Staff, Moderator 17 Juli 2012 7:24
-
18 Juli 2012 4:16
Baik Terima Kasih, akan saya coba saran Anda segera.