Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
susan_151615
Yak Posting Veteran
99 Posts |
Posted - 2008-10-16 : 05:24:39
|
hi i have a web page which is going to display items in the datagrid based on what the user selects in a calendar and dropdown list and based on his login id so ihave written a code likr\e this Dim AssocID As String AssocID = Convert.ToString(Session.Item("Username")) Dim Connstr As String = "Server=tdl12d08;user id=sa;password=sa;database=ToolsTeam" Dim st2 As String = ("SELECT ALLO.TASK_ID, ALLO.TASK_ALLOC_DATE, ALLO.TASK_ACTUAL_EFFORT, ALLO.TASK_START_DATE, ALLO.TASK_END_DATE, ALLO.TASK_STATUS, ALLO.TASK_DETAILS FROM UST_TASK_ALLOCATION_HISTORY ALLO,UST_TASK_HISTORY HIST WHERE ASSOC_ID =@ASSOC_ID AND ALLO.TASK_STATUS =@STATUS AND HIST.TASK_CREATE_DATE = @TASK_CREATE_DATE AND HIST.TASK_ID=ALLO.TASK_ID ") Dim cn2 As SqlConnection = New SqlConnection(Connstr) cn2.Open() Dim da2 As SqlDataAdapter = New SqlDataAdapter(st2, cn2) da2.SelectCommand.Parameters.Add("@STATUS ", SqlDbType.VarChar).Value = ddlStatus.SelectedValue.ToString() da2.SelectCommand.Parameters.Add(" @ASSOC_ID", SqlDbType.VarChar).Value = AssocID da2.SelectCommand.Parameters.Add("@TASK_CREATE_DATE", SqlDbType.VarChar).Value = txtselect Dim ds2 As New DataSet da2.Fill(ds2) cn2.Close() If ds2.Tables(0).Rows.Count > 0 Then dgcomptask.DataSource = ds2 dgcomptask.DataBind() End Ifbut an error came "object must implement IConvertible" can anyone help me in sorting this outsusan |
|
onlyforme
Starting Member
25 Posts |
Posted - 2008-10-17 : 02:09:59
|
Try the following//To Select specified fields from a table.public SqlDataReader SelectSpecifiedFields(string tablename, string fields, string condition){string connection = getConnection();SqlConnection con = new SqlConnection(connection);con.Open();string qry = "Select " + fields + " from " + tablename + " where " + condition + "";SqlCommand cmd = new SqlCommand(qry, con);SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);return dr;}Then in datagrid bind it as followspublic DataSet LoadMyLocations(string regnid){DataSet ds = member.SelectDataSet("al_userlocations", "locationid,location,streetno+','+streetname as address,city,state,zip,directions", "regnid=" + regnid + "");rgCCDetails.DataSource = ds;rgCCDetails.DataBind();} |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2008-10-17 : 02:16:43
|
quote: Originally posted by onlyforme Try the following//To Select specified fields from a table.public SqlDataReader SelectSpecifiedFields(string tablename, string fields, string condition){string connection = getConnection();SqlConnection con = new SqlConnection(connection);con.Open();string qry = "Select " + fields + " from " + tablename + " where " + condition + "";SqlCommand cmd = new SqlCommand(qry, con);SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);return dr;}Then in datagrid bind it as followspublic DataSet LoadMyLocations(string regnid){DataSet ds = member.SelectDataSet("al_userlocations", "locationid,location,streetno+','+streetname as address,city,state,zip,directions", "regnid=" + regnid + "");rgCCDetails.DataSource = ds;rgCCDetails.DataBind();}
Susan's code is in vb.net your reply is in c# |
|
|
susan_151615
Yak Posting Veteran
99 Posts |
Posted - 2008-10-17 : 03:50:09
|
hi thank u so much for replyingbut i forgot to tell u am using javascrip-t function in drop down list so i included a line in javascript for the form to submit again now its working quite finesusan |
|
|
|
|
|
|
|