Pls could anyone help me how to get data from combo box with my following code
i used txt_app_code for combo box name. -
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Linq;
-
using System.Text;
-
using System.Windows.Forms;
-
-
namespace WindowsFormsApplication8
-
{
-
-
public partial class frm_Application_Details : Form
-
{
-
public ADODB.Connection con = new ADODB.Connection();
-
public ADODB.Recordset rs = new ADODB.Recordset();
-
public string ConStr;
-
public string db_Server;
-
public string db_port;
-
public string db;
-
public string db_User;
-
public string db_Pass;
-
public string query;
-
-
-
public frm_Application_Details()
-
{
-
InitializeComponent();
-
}
-
-
-
-
-
private void button2_Click(object sender, EventArgs e)
-
{
-
if (txt_App_Code.Text == "")
-
{
-
MessageBox.Show("Please Enter the Application Code");
-
return;
-
}
-
if (txt_App_Name.Text == "") { MessageBox.Show("Please Enter the name"); return; }
-
if (txt_Start_Date.Text == "") { MessageBox.Show("Please Enter the Date and Time"); return; }
-
-
query = "select * from application_m where ApplicationCode='" + txt_App_Code.Text + "'";
-
rs.Open(query, con, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, -1);
-
if (rs.EOF == false)
-
{
-
rs.Close();
-
MessageBox.Show("Application Code is Already used. Please Enter Different Application code");
-
return;
-
}
-
else
-
{
-
rs.Close();
-
query = "Insert Into application_m(ApplicationCode,ApplicationName,StartDate) Values('" + txt_App_Code.Text + "','" + txt_App_Name.Text + "',now())";
-
rs.Open(query, con, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, -1);
-
MessageBox.Show("Application details saved");
-
}
-
}
-
-
private void frm_Application_Details_Load(object sender, EventArgs e)
-
{
-
db_Server = "localhost";
-
db_port = "3306";
-
db = "etechdata";
-
db_User = "root";
-
db_Pass = "";
-
ConStr = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" + db_Server + ";PORT=" + db_port + ";DATABASE=" + db + ";UID=" + db_User + ";PWD=" + db_Pass + ";OPTION=3";
-
//OdbcCon.ConnectionString = ConStr;
-
try
-
{
-
-
con.Open(ConStr, null, null, 0);
-
-
}
-
catch (System.Data.Odbc.OdbcException Ex)
-
{
-
-
MessageBox.Show("Could not access the database.\r\nPlease make sure you completed the fields with the correct information and try again.\r\n\r\nMore details:\r\n" + Ex.Message, "Database connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);
-
}
-
}
-
-
3 5512
I don't understand your question... what data do you need to get? You're already calling txt_App_Code.Text to get the currently selected item.
Do you need something else? Please be more specific about your question.
Hi gary tnx for replying me..
i need to get the data from database and populate in the combo box.
Here is how I retrieve data from my database to populate the comboBox: -
// Set query to retrieve clients
-
String query = "SELECT id, name FROM tblClients";
-
// Execute query
-
SqlDataAdapter clientsDA = new SqlDataAdapter(query, database_con);
-
// Fill dataset
-
DataSet clientsDS = new DataSet();
-
clientsDA.Fill(clientsDS);
-
// Add clients list to the comboBox
-
this.comboBoxClients.DataSource = clientsDS.Tables[0];
-
this.comboBoxClients.DisplayMember = "name";
-
this.comboBoxClients.ValueMember = "id";
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Meyer1228 |
last post by:
VB6 - We have three data combo boxes with identical properties, each
pointing to a different data file. We're using an odbc driver with a 4th gl
indexed database. All that is working beautifully. ...
|
by: Andrew |
last post by:
Hello,
I am trying to create a chart whose underlying query is linked to 2
combo boxes on the same form.
I want to pass the values from the combo boxes into the chart query to
allow the chart...
|
by: ZZZ |
last post by:
int dummy=Convert.ToInt32(das.Tables.Rows.ItemArray.ToString());
MessageBox.Show(dummy.ToString());
this.combo_opNaam.SelectedValue=dummy;
...
|
by: sonu |
last post by:
I am working with a window application which will run on every computer
on a network.
but data will be only one machine on network.
i am giving in connection string like..
connectionString =...
|
by: Elena |
last post by:
Hi,
I am filling in a combobox. I would like to concatenate two fields into the
data combo box and display "last name, first name"
I tried to displaymember = "employee_last_name" & ", " &...
|
by: UGURMURAT |
last post by:
hi
i managed to create adoc to link datagird so I see my external access database table inside the data gird.
i managed to create a data combo box and list the names of the external document
...
|
by: sunilkds |
last post by:
I want to main difference simple Combo box & DataCombo Box @ VB6.0
What is combox.listindex in DataCombo
|
by: sunilkds |
last post by:
How to count total number of items in the Data Combo in Vb6.0
|
by: sunilkds |
last post by:
I want code for how to clear values in the datacombo at run time.
Plz give corect method or solution
|
by: sunilkds |
last post by:
I want code for how to clear values in the datacombo box (not combo box) at run time.
Plz give corect method or solution
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |