Data into textbox from MySql using ASP.net C#

  • Thread starter Allan Kim Jensen
  • Start date
A

Allan Kim Jensen

Hello,

I am trying to retrieve data from a MySql database using ASP.net, and it
works fine when putting the result into a
gridview (Code provided in the end of this mail).

However, I'd like to get the result into a textbox. Not the entire table,
but just one cell.
If for instance, the name "Bill" appears in the culumn named "FirstName", at
the row with PersonID = 5, I'd like this to go in a textbox using something
like "select FirstName where PersonID = 5"

Furthermore I would like to retrieve the date into variables so that I can
populate a table.

How can I do that!

Tahnks in advance.

This is the code:
<script runat="server">

private const string ConnStr = "Driver={MySQL ODBC 3.51 Driver};" +

"Server=localhost;Database=db1;uid=xxxx;pwd=yyyyy;option=3";

protected override void OnInit(EventArgs e)

{

base.OnInit(e);

using(OdbcConnection con = new OdbcConnection(ConnStr))

using(OdbcCommand cmd = new OdbcCommand("Select * from table1", con))

{

con.Open();

dgrAllNames.DataSource = cmd.ExecuteReader(

CommandBehavior.CloseConnection |

CommandBehavior.SingleResult);

dgrAllNames.DataBind();

}

}

</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Displaying Records from MySQL 'Names' table</title>

<style type="text/css">

body { font: 100% Verdana; }

</style>

</head>

<body>

<center><p>All records in the 'Names' table:</p></center>

<asp:DataGrid ID="dgrAllNames" HorizontalAlign="Center"

CellPadding="3" Runat="server" />

</body>

</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top