T
Teep
Below is my code for dropdownlist that is populated from a SQL table.
After a selection from the ddl, a datagrid is suppose to come up
pertaining to the information selected, but I keep getting a DNS
error. I developed this "simple" page but so far it is not simple!
argh!
<%@ Page Language="VB" Debug="true" Explicit="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SQLClient" %>
<script runat="server">
Dim strConn as string =
"server=abcdserver;database=acct_payable;trusted_connection=true"
Sub Page_Load(Source as Object, E as EventArgs)
if not Page.IsPostBack then
doData()
end if
End Sub
Sub doQuery(Source as Object, E as EventArgs)
'Sub doQuery is for the datagrid
'This may be the source of DSN errors - the sql statement
Dim supname as string
Dim MySQL = "SELECT splr_name, splr_name, splr_addr, " & _
"splr_city FROM tbl_ap_vendors WHERE splr_name='" & supname &
"'"
Dim MyConn as New SQLConnection(strConn)
Dim ds as DataSet=New DataSet()
Dim Cmd as New SQLDataAdapter(MySQL,MyConn)
Cmd.Fill(ds,"tbl_ap_vendors")
'MyDataGrid is for the datagrid to fill
MyDataGrid.Datasource=ds.Tables("tbl_ap_vendors").DefaultView
MyDataGrid.DataBind()
End Sub
Sub doData()
'Sub doData is for the dropdownlist
Dim strSQL =
"server=abcdserver;database=acct_payable;trusted_connection=true"
Dim Conn as new SQLconnection(strConn)
strSQL = "select splr_name from tbl_ap_vendors ORDER BY
splr_name"
Dim Cmd as New SQLCommand(strSQL,Conn)
Conn.Open()
MyDropDownList.DataSource = Cmd.ExecuteReader()
MyDropDownList.DataBind()
End Sub
Function FixDR (sItem) as String
'Function FixDR is for null fields
if Not sItem is System.DBNull.Value then FixDR=sItem
End Function
</script>
<html>
<head>
<title>Testing a dropdownlist and datagrid</title>
</head>
<body>
<Form id="form1" runat="server">
<div align="center"><table> <tr>
</tr>
<tr>
<!-- HTML code to display the DropDownList on the screen for user
input
list is populated by a SQL table and selection bring up DataGrid -->
<td align="center" valign="Top" Colspan="2"><hr>
<b><i><font Color="#0000FF">Using a DropDownList and a
DataGrid:</font></i></b>
<aspropDownList id="MyDropDownList" datatextfield="splr_name"
runat="server" />
<asp:Button id="button" Text="Select Supplier Name" onClick="doQuery"
runat="server" />
<!-- HTML code to display the DataGrid on the screen selection is
determined from user
input selection from DropDownList -->
<aspatagrid
Id="MyDataGrid"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
EnableViewState="false">
</aspataGrid>
</td>
</tr>
</table></div>
</Form>
</body>
</html>
After a selection from the ddl, a datagrid is suppose to come up
pertaining to the information selected, but I keep getting a DNS
error. I developed this "simple" page but so far it is not simple!
argh!
<%@ Page Language="VB" Debug="true" Explicit="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SQLClient" %>
<script runat="server">
Dim strConn as string =
"server=abcdserver;database=acct_payable;trusted_connection=true"
Sub Page_Load(Source as Object, E as EventArgs)
if not Page.IsPostBack then
doData()
end if
End Sub
Sub doQuery(Source as Object, E as EventArgs)
'Sub doQuery is for the datagrid
'This may be the source of DSN errors - the sql statement
Dim supname as string
Dim MySQL = "SELECT splr_name, splr_name, splr_addr, " & _
"splr_city FROM tbl_ap_vendors WHERE splr_name='" & supname &
"'"
Dim MyConn as New SQLConnection(strConn)
Dim ds as DataSet=New DataSet()
Dim Cmd as New SQLDataAdapter(MySQL,MyConn)
Cmd.Fill(ds,"tbl_ap_vendors")
'MyDataGrid is for the datagrid to fill
MyDataGrid.Datasource=ds.Tables("tbl_ap_vendors").DefaultView
MyDataGrid.DataBind()
End Sub
Sub doData()
'Sub doData is for the dropdownlist
Dim strSQL =
"server=abcdserver;database=acct_payable;trusted_connection=true"
Dim Conn as new SQLconnection(strConn)
strSQL = "select splr_name from tbl_ap_vendors ORDER BY
splr_name"
Dim Cmd as New SQLCommand(strSQL,Conn)
Conn.Open()
MyDropDownList.DataSource = Cmd.ExecuteReader()
MyDropDownList.DataBind()
End Sub
Function FixDR (sItem) as String
'Function FixDR is for null fields
if Not sItem is System.DBNull.Value then FixDR=sItem
End Function
</script>
<html>
<head>
<title>Testing a dropdownlist and datagrid</title>
</head>
<body>
<Form id="form1" runat="server">
<div align="center"><table> <tr>
</tr>
<tr>
<!-- HTML code to display the DropDownList on the screen for user
input
list is populated by a SQL table and selection bring up DataGrid -->
<td align="center" valign="Top" Colspan="2"><hr>
<b><i><font Color="#0000FF">Using a DropDownList and a
DataGrid:</font></i></b>
<aspropDownList id="MyDropDownList" datatextfield="splr_name"
runat="server" />
<asp:Button id="button" Text="Select Supplier Name" onClick="doQuery"
runat="server" />
<!-- HTML code to display the DataGrid on the screen selection is
determined from user
input selection from DropDownList -->
<aspatagrid
Id="MyDataGrid"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
EnableViewState="false">
</aspataGrid>
</td>
</tr>
</table></div>
</Form>
</body>
</html>