i got new project again similar to my previous project but i never encountered doing it b4.
hmmmm the scenario is:
i have a drobdownlist for a office_name and a text box for "date"(2007/11/03). after choosing a name from a drop down and writing a date in the textbox when i press the button (ok) a datagrid will appear with its data.
"office_name" field is in table (TM0011) and "year.month.date" is in table (TT0001).
In the gridview.i need to show the time_in,time_out and the name of the employee.
"time in" and "time_out" fields are in the table (TT0001) and syain_name field is in table(TM0001).the only connection they have is the "syain_id".coz both table have "syain_id" as key.
I have two option in my code.. which do u think will most likely work? the inner join or union?
here is my code:
Protected Sub Button_date_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_date.Click
GridView_info.Visible = True
'////////// option 1 //////////////////
Dim MyConn As New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("MS_PKG01ConnectionString").ConnectionString)
MyConn.Open()
Dim stringQuery As String = "select TT0001.*,TM0001.*,TM0011.* from TT0001 inner join TM0001 on TT0001.syain_id = TM0001.syain_id " '+ Request.requerystring("syain_id")
Dim sqldataadapter As New SqlClient.SqlDataAdapter(stringQuery, MyConn)
Dim ds As New DataSet()
sqldataadapter.Fill(ds, "TT0001")
GridView_info.DataSourceID = ""
GridView_info.DataSource = ds
GridView_info.DataBind()
MyConn.Close()
'/////////option 2 ///////////////////
'Dim MyConn As New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("MS_PKG01ConnectionString").ConnectionString)
'MyConn.Open()
'Dim stringQuery As String = " select TT0001.syain_id,TT0001.year,TT0001.month,TT0001.day,TT0001.in_hh,TT0001in_mi,TT0001out_hh,TT0001out_mi From TT0001 Where TT0001.syain_id = TM0001.syain_id and TT0001.syain_id = " + Session("syain_id") + " Union Select TM0001.syain_id,TM0001.syain_name From TM0001 Where TM0001.syain_name = TTM0001.syain_name and TM0001.syain_id = " + Session("syain_id") + " "
'Dim stringQuery2 As String = "SELECT * from tempo_db"
'Dim SQLcommand1 As New SqlClient.SqlCommand("Drop table tempo_db", MyConn)
'SQLcommand1.ExecuteNonQuery()
'Dim SQLcommand2 As New SqlClient.SqlCommand("Create table tempo_db ( year char(4), month(2), day char(2), in_hh(2),in_mi(2), out_hh(2),out_mi(2) )", MyConn)
'SQLcommand2.ExecuteNonQuery()
'Dim sqldataadapter As New SqlClient.SqlDataAdapter(stringQuery, MyConn)
'Dim ds As New DataSet()
'Dim foundrow, temprow As DataRow
'Dim ds2 As New DataSet
'Dim temp_data_table As New DataTable
'sqldataadapter.Fill(ds, "TT0001")
'Dim sqldataadapter2 As New SqlClient.SqlDataAdapter(stringQuery2, MyConn)
'sqldataadapter2.Fill(ds2, "tempo_db")
'Dim date_ctr As Integer
'date_ctr = 1
'GridView_info.DataSourceID = ""
'GridView_info.DataSource = ds
'GridView_info.DataBind()
'MyConn.Close()
End Sub
thank you...
From your description I think JOIN is the proper solution. BTW, you may need Parameterized Query to prevent SQL Injection.Pose again if you have any other problem on this.|||
hi thank you... the problem was just solved awhile ago... but thanks...
btw, are u familiar with hyperlink? coz i dont know how to put hyperlink ...
coz all the data's being shown in my gridview are generated automatically...
how can i put hyperlink on one of the columns if its not coded in html?