DAAB – using stored Procedure

06/07/2009

Database db = DatabaseFactory.CreateDatabase();
 DbCommand cmd = db.GetStoredProcCommand(”EntLibProc”);
DataSet ds = db.ExecuteDataSet(cmd);
GridView1.DataSource = ds; GridView1.DataBind();

My webconfig setting:

<connectionStrings>
<
add name=MyFirstTest providerName=System.Data.SqlClient connectionString=Data Source=MURUGESA-B9EA7D\SQLEXPRESS;Initial Catalog=Murugesan;Integrated Security=True/>
</
connectionStrings>
<
dataConfiguration defaultDatabase=MyFirstTest/>

 

under config section of configuration tag,add this

<section name=dataConfiguration type=Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data/>


Comma delimeter split in C#

13/06/2009

I was given a text file where I need to separate the each email ids from the grouped text.
Each email ids were identified by the character comma(,) delimeter.

My solution resides in single line of code thats GetString method of ASCII class.
You can find this in System.Text namespace.

FileStream fs = new FileStream(”E:\\SLGroupFriends.txt”, FileMode.Open);
byte[] p = new byte[fs.Length];
fs.Read(p, 0, p.Length);
string r = Encoding.ASCII.GetString(p);
string[] result = r.Split(’,');
GridView1.DataSource = result;
GridView1.DataBind();


Retrieving multiple records in C#

08/06/2009

ExecuteDataSet method of DbCommand will returns the multiple rows from the table.

Code Behind:

Database db = DatabaseFactory.CreateDatabase();
string sql = “SELECT * From BankDetails”;
DbCommand cmd = db.GetSqlStringCommand(sql);
DataSet ds = db.ExecuteDataSet(cmd);
GridView1.DataSource = ds;
GridView1.DataBind();

My web.config was:

I simply added this line between ConfigSections tag of Configuration.

<section name=”dataConfiguration” type=”Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data” />

Then connectionstring tag below

<connectionStrings>
<add name=”MyFirstTest”
providerName=”System.Data.SqlClient”
connectionString=”Data Source=(local);database=BankAccount;user id=sa;pwd=murugesan”/>
</connectionStrings>
<dataConfiguration defaultDatabase=”MyFirstTest”/>


Saving BLOB in SQL-Server

20/04/2008

SqlConnection con = new SqlConnection(”Data Source=(Local);Initial Catalog=Pack;user id=sa;pwd=murugesan”);
con.Open();
SqlDataAdapter sd = new SqlDataAdapter(”Select *from Signatures”, con);
SqlCommandBuilder builder = new SqlCommandBuilder(sd);
DataSet ds = new DataSet(”Signatures”);
sd.MissingSchemaAction = MissingSchemaAction.AddWithKey;
FileStream fs=new FileStream(@”D:\\VijayMallya.Jpg”,FileMode.OpenOrCreate,FileAccess.Read);
byte[] size = new byte[fs.Length];
fs.Read(size,0, System.Convert.ToInt32(fs.Length));
fs.Close();
sd.Fill(ds, “Signatures”);
DataRow drow;
drow = ds.Tables["Signatures"].NewRow();
drow["image"] = size;
ds.Tables["Signatures"].Rows.Add(drow);
sd.Update(ds, “Signatures”);
con.Close();


Hello world!

20/04/2008

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!