Wednesday, May 21, 2008

How to add a textbox inside a gridview

First add a gridview in your page and go to the source view of your page and find the gridview inside which you want to add the textbox and you can insert a code as below (the one in bold blue color) and it will add the textbox into the gridview when it is bound to the database object.

Just below it is the code with which you can access these individual textbox in the different rows.
for (int j = 0; j < GridView1.Rows.Count; j++)
Control cnt;
cnt = GridView1.Rows[j].Cells[3].Controls[1];
cnt = GridView1.Rows[j].FindControl("txtValue");
TextBox txtBx = (TextBox)cnt;
//write your code here to maniupulate the content of textbox


Monday, May 12, 2008

How to pass login parameter (username, password) of database to crystal report from code

using CrystalDecisions.Reporting;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;
private void displayReport()
CrystalReportViewer1.EnableDatabaseLogonPrompt = false;
ConnectionInfo connInfo = new ConnectionInfo();
TableLogOnInfo tblLogInfo = new TableLogOnInfo();
TableLogOnInfos tblLogInfos = new TableLogOnInfos();
connInfo.UserID = "usrName";
connInfo.Password = "passwd";
connInfo.ServerName = "database";
tblLogInfo.ConnectionInfo = connInfo;
CrystalReportViewer1.LogOnInfo = tblLogInfos;
CrystalReportViewer1.EnableParameterPrompt = false;
CrystalReportSource1.ReportDocument.FileName=Server.MapPath ("Reports\\crystNewMain.rpt");

Saturday, May 10, 2008

How to pass parameter to crystal report from ASP.NET

Suppose there is a crystal report which expects parameter id and section. Here’s the code that shows how to pass the parameter through
Before this please do not forget to use following namespaces

using CrystalDecisions.Reporting;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;

private void displayReport(number id,string section)

CrystalReportViewer1.EnableParameterPrompt = false;
ParameterFields pFields = new ParameterFields();
ParameterField pField1 = new ParameterField();
ParameterField pField2 = new ParameterField();
ParameterDiscreteValue pDisValue1 = new ParameterDiscreteValue();
ParameterDiscreteValue pDisValue2 = new ParameterDiscreteValue();
pField1.Name = "id";
pField2.Name = "section";
pDisValue1.Value = id;
pDisValue2.Value = section;
CrystalReportViewer1.ParameterFieldInfo = pFields;

Friday, April 18, 2008

System.Data.OracleClient requires Oracle client software version 8.1.7 or greater

Security permissions were not properly set when the Oracle 9i Release 2 client was installed on Windows with NTFS. The result of this is that content of the ORACLE_HOME directory is not visible to Authenticated Users on the machine; this again causes an error while the System.Data.OracleClient is communicating with the Oracle Connectivity software from an ASP.NET using Authenticated User privileges.
To fix the problem you have to give the Authenticated Users group privilege to the Oracle Home directory.

  1. Log on to Windwos as a user with Administrator privileges.
  2. Start Window Explorer and navigate to the ORACLE_HOME folder.
  3. Choose properties on the ORACLE_HOME folder.
  4. Click the "Security" tab of the "Properties" window.
  5. Click on "Authenticated Users" item in the "Name" list.
  6. Uncheck the "Read and Execute" box in the "Permissions" list under the "Allow" column.
  7. Re-check the "Read and Execute" box under the "Allow" column
  8. Click the "Advanced" button and in the "Permission Entries" verify that "Authenticated Users" are listed with permission = "Read & Execute", and Apply To = "This folder, subfolders and files". If not, edit that line and make sure that "Apply To" drop-down box is set to "This folder, subfolders and files". This should already be set properly but it is important that you verify it.
  9. Click the "Ok" button until you close out all of the security properties windows. The cursor may present the hour glass for a few seconds as it applies the permissions you just changed to all subfolders and files.
  10. Reboot, to assure that the changes have taken effect.

Thursday, April 17, 2008

Running a stored procedure from ASP dot net

Suppose there is a procedure
,usrValid out NUMBER) AS

Now in C# we write code the following way
Public Boolean validateUser(string pusrname,string pusrpass)
OracleConnection con = new OracleConnection(appParams.connString);
//instead of appParams.connString use connection string for your database
sql = " begin validateuser(:uName,:uPasswd,:uValid); end;";
OracleParameter p1 = new OracleParameter();
p1.OracleType = OracleType.VarChar;
OracleParameter p2 = new OracleParameter();
p2.OracleType = OracleType.VarChar;
OracleParameter p3 = new OracleParameter();//dept
p3.OracleType = OracleType.Number;
p1.ParameterName = "uName";
p2.ParameterName = "uPasswd";
p3.ParameterName = "uValid";
OracleCommand cmd = new OracleCommand(sql, con);
cmd.Parameters.Add(p1); cmd.Parameters.Add(p2); cmd.Parameters.Add(p3);
cmd.CommandText = sql;
return true;
return false;
Catch(System.exception ex)
return false;