hi ,
i am a new to c#..could you help me out to solve this issue..
i am retriving a value from database and then i have to display it in html table.
the table contains 25 columns..the code :
default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public OleDbConnection con = new OleDbConnection(System.Configuration.ConfigurationManager.AppSettings["ConStr"]);
protected void Button1_Click1(object sender, EventArgs e)
{
try
{
con.Open();
string srtSQry = "Select mobile, branch_code from branch_master Where branch_id =('" + branch_id.Text + "') ";
OleDbDataReader client_idReader;
OleDbCommand Comm = new OleDbCommand(srtSQry, con);
client_idReader = Comm.ExecuteReader();
while (client_idReader.Read() == true)
{
client_name.Text = Convert.ToString (client_idReader["mobile"]);
client_pan.Text = Convert.ToString (client_idReader["branch_code"]);
}
client_idReader.Close();
}
catch (Exception ex)
{
}
finally
{
con.Close();
}
}
}
default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Table displaytitle>
head>
<body>
<form id="form1" runat="server">
Enter Branch ID :
<asp:TextBox ID="branch_id" runat="server">asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Height="49px" onclick="Button1_Click1"
Text="click me" Width="201px" />
<br />
<div id="txtHint">
Client Name : <asp:TextBox ID="client_name" runat="server">asp:TextBox>
<br />
Client PAN No:<asp:TextBox ID="client_pan" runat="server">asp:TextBox>
<br />
div>
form>
<script type="text/javascript">
function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
/*
for entering only numbers in the text box */
document.getElementById("branch_id").onkeypress=function(e){
var e=window.event || e
var keyunicode=e.charCode || e.keyCode
//Allow alphabetical keys, plus BACKSPACE and SPACE
return (keyunicode>=48 && keyunicode<=57)? true: false
}
script>
<script runat="server">
script>
body>
html>
webcofig:
in webcofig i have included the connection string
Loading
Kirtan PatelPosted Feb 5, 2010, 7:04 AM
i can solve your problem Quickly ...
navin thangarajPosted Feb 5, 2010, 3:38 AM
navin thangarajPosted Feb 5, 2010, 3:18 AM
can i write ur code in the default.aspx.cs file itself ?
can i send my file to ur gmail id ?
could u help me out plz..
shyamalaPosted Feb 5, 2010, 3:07 AM
shyamalaPosted Feb 5, 2010, 2:36 AM
You should write in this code for DBExecute in database connection file in App_Code folder..can you understand..??
public DataTable DBExecute(string query)
{
System.Data.DataTable dt = null;
try
{
dt = new System.Data.DataTable();
connectionString = (string)ConfigurationManager.AppSettings["ConStr"];
con.ConnectionString = connectionString;
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = query;
da.SelectCommand = cmd;
dt.Reset();
da.Fill(dt);
}
catch(SqlException sqlex)
{
HttpContext.Current.Response.Write(sqlex);
}
finally
{
con.Close();
con.Dispose();
}
return dt;
}
navin thangarajPosted Feb 5, 2010, 2:27 AM
i am getting a value from the user... branch_id and aftr clicking the button,
i am fetching other 10 values from the sql database ...
i have modified my code as u said : but it shows some error
protected void Button1_Click1(object sender, EventArgs e)
{
try
{
con.Open();
//string srtSQry = "Select mobile, branch_code from branch_master Where branch_id =('" + branch_id.Text + "') ";
//OleDbDataReader client_idReader;
//OleDbCommand Comm = new OleDbCommand(srtSQry, con);
//client_idReader = Comm.ExecuteReader();
DataTable dt=new DataTable();
// while (client_idReader.Read() == true)
// {
dt=con.DBExecute("Select mobile, branch_code from branch_master Where branch_id =('" + branch_id.Text + "') ");
mobile.innerhtml=dt.Rows[0]["mobile"].ToString();
branch_code.innerhtml=dt.Rows[0]["branch_code"].ToString();
//client_name.Text = Convert.ToString (client_idReader["mobile"]);
// client_pan.Text = Convert.ToString (client_idReader["branch_code"]);
// }
//client_idReader.Close();
}
error is :
CS1061: 'System.Data.OleDb.OleDbConnection' does not contain a definition for 'DBExecute' and no extension method 'DBExecute' accepting a first argument of type 'System.Data.OleDb.OleDbConnection' could be found (are you missing a using directive or an assembly reference?)
could help me out plz..
i need to submit this code with in 2 hrs
shyamalaPosted Feb 5, 2010, 2:13 AM
in c#
first include
DataTable dt=new DataTable();
OleDbConnection con = new OleDbConnection
dt=con.DBExecute("Select mobile, branch_code from branch_master Where branch_id =('" + branch_id.Text + "') ";
mobile.innerhtml=dt.Rows[0]["mobile"].ToString();
branch_code.innerhtml=dt.Rows[0]["branch_code"].ToString();