S B  Ray

S B Ray

  • NA
  • 11
  • 0

problem with data display

Jan 9 2008 4:28 AM

Dear All,

I have a table in oracle database having 4 fields- ID,code,name,password.

I have a web form in which I am accepting a value for code from the user and want to display the entire record in a gridview.

For doing this I having a label,textbox, button and gridview in a web page.

I have written the following code for the button which searches the record and populates the gridview.

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 Romany.DAL;

protected void btnsrch_Click(object sender, EventArgs e)

{

string val = TextBox1.Text.ToString().Trim();

//int val1 = Int32.Parse(val);

Romany.DAL.DBManager db = new DBManager();DataSet ds1 = db.getRecord(val); // this is the method of the class in my DAL

GridView1.DataSource = ds1;

//GridView1.DataMember = ds1.Tables["myusr"].TableName.ToString();

GridView1.DataBind();

 

}

I have a DAL which has a method called getRecord(),that actually connects to the database, fetches the record and then returns the record as a Dataset to

button event handler mentioned above. The method is as follows:

 

public class DBManager

{

public DBManager()

{

//

// TODO: Add constructor logic here

//

}

public string getConnString(string strname)

{

string connstr = ConfigurationManager.ConnectionStrings[strname].ConnectionString;return connstr;

 

}

public DataSet getRecord(string cd)

{

//string cd1 = cd;

string cd1 = cd;

string str = getConnString("ConnectionString2");

OracleConnection objConnection = new OracleConnection();

objConnection.ConnectionString = str;

try

{

if (objConnection.State == ConnectionState.Closed)

{

objConnection.Open();

}

string cmdtxt = "select * from users where code ='" + cd1 + "'";

//OracleCommand objCommand = new OracleCommand(cmdtxt, objConnection);

//OracleDataReader dr = objCommand.ExecuteReader();

DataSet ds = new DataSet();

OracleDataAdapter oda = new OracleDataAdapter(cmdtxt, objConnection);

oda.Fill(ds, "usr");

if (ds.Tables["usr"].Rows.Count > 0)

return ds;

else

return null;

 

 

}

finally

{

objConnection.Close();

}

}

}

The problem is that this was working fine.But it stopped working after I dropped the table users and recreated it with same name but one more column which I made primary key, Identity. The insert operation is still working with the old code and new table.

Can't really figure out as to what went wrong.

Any help that solves this issue will be gratefully accepted.

Thanks.


Answers (1)