.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

using dataset,datarow and connectionstring displaying allrecords separated by coma in textbox by cal

Posted By: Rama Krishna     Posted Date: August 21, 2009    Points:2   Category :C#
i am using this code under page load event
is any wrong in it?
-----------------------------------------------------
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using SunbrightDataAccess;
using SunbrightUtilities;


public partial class _Default : System.Web.UI.Page
{


protected void Page_Load(object sender, EventArgs e)
{
Dataset ds=new DataSet();
DataRow dr = new DataRow();

try
{
sqlQuery = "exec uspGetContactRecords " + ContactID;
Loger.writeLog(sqlQuery);
ds = SunbrightDB.DataAccess.ExecuteDataset((string)Application.Get("ConnectionString"), sqlQuery);
}
catch (System.Exception exp)
{
Loger.writeLog(exp.ToString());
}

String str = "";

foreach (DataRow row in tblContact.Rows)
{
str = str + ((row["FullName"] == DBNull.Value) ? "" : row["FullName"].ToString() + ",");
}
if (str.Length > 0)
str = str.Remove(str.Length - 1, 1);

TxtTO.Text = str;

Responses
Author: Akhil Raj       [Moderator]      
Posted Date: August 22, 2009     Points: 5   

hi rama... don't mistake me.. Are you asking any wrong in it? are you tried this? please try and ask if any error . so you got confident in code. For better performance code you can ask...

Author: Rama Krishna             
Posted Date: August 22, 2009     Points: 5   

no,akhil i asked in forum after debug it only
the page name is compose.aspx,under web.config file i declare the connection string,it is source code,firstone is .cs file code,but debug it is succesfully work,
but no records dispay in text box
---------------------------------------------------------------------------------

@ 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>Untitled Page</title>
<style type="text/css">
.style3
{
width: 128px;
}
.style5
{
height: 12px;
width: 128px;
}
.style6
{
height: 12px;
}
.style8
{
width: 110px;
}
.style9
{
width: 110px;
height: 22px;
}
.style10
{
height: 22px;
width: 674px;
}
.style11
{
width: 110px;
height: 98px;
}
.style12
{
height: 98px;
width: 674px;
}
.style13
{
width: 674px;
}
#tbl2
{
height: 241px;
width: 804px;
}
.style14
{
width: 128px;
height: 240px;
}
.style15
{
height: 240px;
}
</style>
</head>
<body>
<form id="formdefault" runat="server">
<div>

</div>
<table id=tbl1 runat="server" bgcolor="#98CBCB">
<tr>
<td class="style3">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="LblTO" runat="server" Text="TO"></asp:Label>
</td>
<td>
<asp:TextBox ID="TxtTO" runat="server" DataSourceID="SqlDataSource1"
Width="660px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="LblCC" runat="server" Text="CC"></asp:Label>
</td>
<td>
<asp:TextBox ID="TxtCC" runat="server" Width="660px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="LblBCC" runat="server" Text="BCC"></asp:Label>
</td>
<td>
<asp:TextBox ID="TxtBCC" runat="server" Width="660px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="LblST" runat="server" Text="SUBJECT"></asp:Label>
</td>
<td>
<asp:TextBox ID="TxtSBG" runat="server" Width="660px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style5">
</td>
<td class="style6">
<asp:Label ID="LblMG" runat="server" Text="MESSAGE"></asp:Label>
</td>
</tr>

<tr>
<td class="style14">
</td>
<td class="style15">
<asp:TextBox ID="TxtMSG" runat="server" Height="253px" Width="650px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
&nbsp;</td>
<td>
<asp:Button ID="BtnSD" runat="server" Text="SEND" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="BtnCR" runat="server" Text="CLEAR"
Height="27px" Width="56px" />
</td>
</tr>
</table>
</form>
</body>
</html>

Author: Rama Krishna             
Posted Date: August 22, 2009     Points: 5   

actually i have one doubt, syntax for creating the connection in one form of project from the 'connection string' which was declared in web.config file of that project?

Author: Akhil Raj       [Moderator]      
Posted Date: August 22, 2009     Points: 5   

if you declare connection using appSettings you can call like the following:

ConfigurationManager.AppSettings["conname"]

Here "conname" is the name for Connection String appSettings

If you use ConnctionStrings tag you can call like the following:

ConfigurationManager.ConnectionStrings["con"].ConnectionString;

Author: Akhil Raj       [Moderator]      
Posted Date: August 22, 2009     Points: 5   

the only mistake you did in the code is tblContacts.Rows..

I didnt find anything in the code fix for tblContacts. You got the values in Dataset named ds.

So just in the foreach statement

foreach (DataRow row in ds.Tables[0].Rows)
{
...
}

For this i think you got the tables values in the ds. No need to create DataRow.. in the second line of page load... and also check in the DataSet declaration that DataSet spelling is wrong..



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend