RSS

ListView Connecting to Database …

28 Jan

public DataTable SelectTable(string connStr, string Query)
{
DataTable dt;
SqlConnection cn;
SqlCommand cmd;
SqlDataAdapter adapter;
try
{
using (cn = new SqlConnection(connStr))
{
cn.Open();
cmd = new SqlCommand(Query, cn);
adapter = new SqlDataAdapter(cmd);
dt = new DataTable();
adapter.Fill(dt);
cn.Close();
return dt;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, “”);
return null;
}
finally
{
cmd = null;
cn = null;
dt = null;
adapter = null;
}
}

public doLoad ()
{
DataTable dt = SelectTable(“Data Source=ServerName;Initial Catalog=DataBaseName;Persist
Security Info=True;User ID=UserName;Password=Password”, “select * from ListTable”);
this.listView1.DataBindings.Add(“property_name”, dt, “data_member_name”);
}
жич : “Data Source=ServerName;Initial Catalog=DataBaseName;Persist Security Info=True;User ID=UserName;Password=Password” – нь Connection String

нэг хүн асууж байсан санагдаж байна. энэ дээрх бол дата баазаасаа уншиж байгаа хэсэг бөгөөд insert хийхдээ ListView- ээс ямарч хамааралгүй шууд баазад нь insert хийгээд дээрх кодоор уншихад болно гэж бодож байна. за амжилт. өөр маш олон арга бас бий…

 
1 Comment

Posted by on January 28, 2009 in My

 

One response to “ListView Connecting to Database …

  1. byamba

    November 4, 2009 at 11:14 am

    hey mash ih bayrallaa tanid belen game-nii source code bgaa yuu jishee n poker entr bi card game hiih gesen chin tiimerhuu jishee oldsongvi

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: