D
Dave1031
I am trying to translate some VB code into C#.
THis works in VB: Link button in repeater controll is clicked....
Sub repeater1_ItemCommand(sender As Object, e As RepeaterCommandEventArgs)
If e.CommandName = "Detail" then
Dim x as Label = e.Item.FindControl("lblTitleID")
Dim sTitleID as String = x.Text
DataGrid1.DataSource = getDetail(sTitleID)
DataGrid1.DataBind()
End If
End Sub
....getDetail function is called to populate a datagrid with the details....
Function getDetail(TitleID as String) as SqlDataReader
Const strConnString as String = "server=localhost;uid=sa;pwd=xxx;
database=pubs"
Dim objConn as New SqlConnection(strConnString)
Dim strSQL as String
strSQL = "SELECT * FROM titles WHERE title_id = @TitleID"
Dim objCmd as New SqlCommand(strSQL, objConn)
Dim paramTitleID as SqlParameter
paramTitleID = New SqlParameter("@TitleID", SqlDbType.VarChar, 10)
paramTitleID.Value = TitleID
objCmd.Parameters.Add(paramTitleID)
objConn.Open() 'Open the connection
Return objCmd.ExecuteReader(CommandBehavior.CloseConnection)
End Function
.... but this cvode in c# throws numerous errors...
void ShowDetails(object sender, EventArgs e)
void DataGrid1_ItemCommand(object sender, DataGridCommandEventArgs e)
{
string sTitleID =
DataGrid1.DataKeys[DataGrid1.SelectedIndex].ToString();
DataGrid1.DataSource = getDetail(sTitleID);
DataGrid1.DataBind();
}
void getDetail(sTitleID) SqlDataReader
{
const string strConnString =
"server=localhost;uid=sa;pwd=xxx;database=pubs";
SqlConnection objConn = new SqlConnection(strConnString);
const string strSQL = "SELECT * FROM titles WHERE title_id =
@TitleID";
SqlCommand objCmd = new SqlCommand(strSQL, objConn);
SqlParameter paramTitleID;
paramTitleID = new SqlParameter("@TitleID", SqlDbType.VarChar,
10);
paramTitleID.Value = TitleID;
objCmd2.Parameters.Add(paramTitleID);
objConn2.Open();
return objCmd.ExecuteReader(CommandBehavior.CloseConnection);
objConn2.Close();
}
Can anyone give me some hints on where I going wrong? Specifically, how do
I call the procedure to populate the sata reader?
THis works in VB: Link button in repeater controll is clicked....
Sub repeater1_ItemCommand(sender As Object, e As RepeaterCommandEventArgs)
If e.CommandName = "Detail" then
Dim x as Label = e.Item.FindControl("lblTitleID")
Dim sTitleID as String = x.Text
DataGrid1.DataSource = getDetail(sTitleID)
DataGrid1.DataBind()
End If
End Sub
....getDetail function is called to populate a datagrid with the details....
Function getDetail(TitleID as String) as SqlDataReader
Const strConnString as String = "server=localhost;uid=sa;pwd=xxx;
database=pubs"
Dim objConn as New SqlConnection(strConnString)
Dim strSQL as String
strSQL = "SELECT * FROM titles WHERE title_id = @TitleID"
Dim objCmd as New SqlCommand(strSQL, objConn)
Dim paramTitleID as SqlParameter
paramTitleID = New SqlParameter("@TitleID", SqlDbType.VarChar, 10)
paramTitleID.Value = TitleID
objCmd.Parameters.Add(paramTitleID)
objConn.Open() 'Open the connection
Return objCmd.ExecuteReader(CommandBehavior.CloseConnection)
End Function
.... but this cvode in c# throws numerous errors...
void ShowDetails(object sender, EventArgs e)
void DataGrid1_ItemCommand(object sender, DataGridCommandEventArgs e)
{
string sTitleID =
DataGrid1.DataKeys[DataGrid1.SelectedIndex].ToString();
DataGrid1.DataSource = getDetail(sTitleID);
DataGrid1.DataBind();
}
void getDetail(sTitleID) SqlDataReader
{
const string strConnString =
"server=localhost;uid=sa;pwd=xxx;database=pubs";
SqlConnection objConn = new SqlConnection(strConnString);
const string strSQL = "SELECT * FROM titles WHERE title_id =
@TitleID";
SqlCommand objCmd = new SqlCommand(strSQL, objConn);
SqlParameter paramTitleID;
paramTitleID = new SqlParameter("@TitleID", SqlDbType.VarChar,
10);
paramTitleID.Value = TitleID;
objCmd2.Parameters.Add(paramTitleID);
objConn2.Open();
return objCmd.ExecuteReader(CommandBehavior.CloseConnection);
objConn2.Close();
}
Can anyone give me some hints on where I going wrong? Specifically, how do
I call the procedure to populate the sata reader?