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
alaa
NA
166
84.8k
how to load multi comboboxs from diffrent table in database
Dec 8 2012 3:44 PM
how to load multi comboboxs from diffrent table in database
i build a class where i can connect database and put my datatabell here it is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace SELECTComboboxCLASSES
{
class DB
{
SqlConnection connet;
SqlCommand cmd;
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt;
#region connection and open it
private void Intialize(CommandType CT, string SPSQL)
{
connet = new SqlConnection();
cmd = new SqlCommand();
connet.ConnectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Educational System;Data Source=DREAMS";
cmd.Connection = connet;
cmd.CommandType = CT;
cmd.CommandText = SPSQL;
connet.Open();
}
#endregion
#region connection and open it
public DataTable RunSELECT(string Select)
{
Intialize(CommandType.Text, Select);
dt = new DataTable();
dt.Load(cmd.ExecuteReader());
connet.Close();
return dt;
}
#endregion
}// end of the class
}
then i make an other class where i cann run my select command and pass the value from and to data base
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace SELECTComboboxCLASSES
{
class SELECTCOMBOBOX
{
DB getconnetion = new DB();
public bool DropdownList1(string ValueMemberData, string DisplayMemberData)
{
string query = string.Format("SELECT jobid, jobname FROM Job ORDER BY jobid", ValueMemberData, DisplayMemberData);
if (getconnetion.RunSELECT(query).Rows.Count == 1)
return true;
else
return false;
}
public bool DropdownList2(string ValueMemberData, string DisplayMemberData)
{
string query = string.Format("SELECT Userid, username FROM User ORDER BY userid", ValueMemberData, DisplayMemberData);
if (getconnetion.RunSELECT(query).Rows.Count == 1)
return true;
else
return false;
}
public bool DropdownList3(string ValueMemberData, string DisplayMemberData)
{
string query = string.Format("SELECT Rolid, Rolname FROM Rols ORDER BY rolid", ValueMemberData, DisplayMemberData);
if (getconnetion.RunSELECT(query).Rows.Count == 1)
return true;
else
return false;
}
}
}
and last i put three combobox where i want it to get data in load how can i complete this work please help i am still beginner but i make many trials but still nothing !!!
what is the correct one ???
Reply
Answers (
3
)
What setup files I have to give my client?
How to validate user input in Windows Forms textbox so that no Letters/Alphabets can be pasted