Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mysql Parameter query. 1

Status
Not open for further replies.

Algorrob

Programmer
Feb 2, 2005
1
GB
Trying to get my head around Using mysql with vb.net. Can someone please help me out with an sql statement. This started out as some downloaded code which I've tried to adapt but seem to mess it up with parameters:


<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.odbc" %>

<html>
<script language="VB" runat="server">

Sub GetExpenses_Click(Sender As Object, E As EventArgs)

Dim DS As DataSet
Dim MyConnection As odbcConnection
Dim MyCommand As odbcDataAdapter

Dim SelectCommand As String = "select DATE_FORMAT(Date, '%d/%m/%Y %a') as 'Date', Detail, CONCAT('£', Amount) As Cost, Fuel " & _
"from expenses where fuel = ?" ///*** This is my problem ***

MyConnection = New odbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;" & _
"Database=SomeDb;uid=Fred;pwd=Bloggs;Port=3306;Option=3;")
MyCommand = New odbcDataAdapter(SelectCommand, MyConnection)

MyCommand.SelectCommand.Parameters.Add(New odbcParameter(?, odbcDbType.Enum)) ''' and this
MyCommand.SelectCommand.Parameters("?").Value = MySelect.Value

DS = new DataSet()
MyCommand.Fill(DS, "employees")

MyDataGrid.DataSource=DS.Tables("employees").DefaultView
MyDataGrid.DataBind()
End Sub

</script>

<body style="font: 10pt verdana">

<form runat="server">

<h3><font face="Verdana">Parameterized Select to a DataGrid Control</font></h3>

Select a State:

<select id="MySelect" runat="server">
<option>1</option>
<option>0</option>
</select>

<input type="submit" OnServerClick="GetAuthors_Click" Value="Get Authors" runat="server"/><p>

<ASP:DataGrid id="MyDataGrid" runat="server"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
EnableViewState="false"
/>

</form>

</body>
</html>
 
Try casting your enum to its base type. If none was explicitly defined, I think Integer is the default:

Code:
MyCommand.SelectCommand.Parameters.Add(New odbcParameter("?", (Integer) MySelect.Value))

Also try a hardcoded value that you know will return results for troubleshooting purposes:

Code:
MyCommand.SelectCommand.Parameters.Add(New odbcParameter("?", 100))

If the hardcoded value works, there is probably something wrong with type casting somewhere.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top