TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maneesh A N
NA
179
108.2k
how to give connection
Nov 9 2013 1:11 PM
public void fnLoadListbox(ListBox cboGrid, string strQuery)
{
try
{
string s = ClsConnect.conSql.State.ToString();
if (s == "Open")
{
ClsConnect.conSql.Close();
}
ClsConnect.conSql.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
//cmd = ClsConnect.conSql.CreateCommand();
cmd.CommandText = strQuery;
dcId = new DataColumn("idField", typeof(int));
dcName = new DataColumn("nameField", typeof(string));
dt = new DataTable();
dt.Columns.Add(dcId);
dt.Columns.Add(dcName);
dr = cmd.ExecuteReader();
while (dr.Read())
{
DataRow rowData = dt.NewRow();
rowData["idField"] = dr[0];
rowData["nameField"] = dr[1];
dt.Rows.Add(rowData);
}
dr.Close();
cboGrid.DataSource = dt;
cboGrid.ValueMember = "idField";
cboGrid.DisplayMember = "nameField";
cboGrid.BringToFront();
cboGrid.Visible = true;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return;
}
finally
{
ClsConnect.conSql.Close();
}
Reply
Answers (
0
)
c# error,how to save
set class name and object name at run time