hello everyone ;
what is the syntax of list box in insert querry. i am using c-sharp .
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Koteswararao MallisettiRank #2,740 · 511 reputationPosted Aug 6, 2010, 1:23 AM EDT
it will give the list box selected item textvalue you directly use it in the insert Query
sumaira manzoor hussain khanRank #8,900 · 214 reputationPosted Aug 6, 2010, 1:41 AM EDT
please, you will check my querry . because i apply listbox syntax directly in my code . but my query give error to me.
this is my query
MY_SQL_NEW_QUR.Access("insert into laboratory([laboratoryrecieptid],[patientid],[patientname],[doctorname],[departmentname],[laboratoryselectedservices],[laboratorycharges],[totalcharges])values('"+textBox_laboratory_reciept_id.Text+"','"+textBox_patient_id.Text+"','"+textBox_patient_name.Text+"','"+textBox_doctor_name.Text+"','"+textBox_department_name.Text+"',listBox_selected_services.Text, listBox_lab_charges.Text,'"+textBox_total_charges.Text+"')",connection.My_Get());
Satyapriya NayakRank #47 · 31.5K reputationPosted Aug 6, 2010, 5:12 AM EDT
I wonder what you are looking for the solution,first the question iam not very clear.I mean to say that in listbox previously items are bound to it or not if yes i have a solution given below
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlDataAdapter ad = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
string str;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ListBox1.Items.Add("HR");
ListBox1.Items.Add("IT");
ListBox1.Items.Add("MK");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
str = "insert into emp values('" + TextBox1.Text + "','" + ListBox1.SelectedItem.Text + "')";
cmd = new SqlCommand(str, conn);
cmd.ExecuteNonQuery();
conn.Close();
Response.Write("Records Inserted");
clear();
}
void clear()
{
TextBox1.Text = "";
}
}
Iam attaching a sample program you run it to get the desired output.
Thanks
If this helps you mark it as Accepted Answer
sumaira manzoor hussain khanRank #8,900 · 214 reputationPosted Aug 6, 2010, 6:18 AM EDT
sir, i wrote the listbox1.selecteditem in my code but .Text is missing in my code. it means .Text is not in the library
sumaira manzoor hussain khanRank #8,900 · 214 reputationPosted Aug 6, 2010, 6:24 AM EDT
i am sending my insert query . the error are occur in the list box syntax. the wrong syntax is in orange color. actually, my problem is syntax of list box in insert query .
MY_SQL_NEW_QUR.Access("insert into laboratory([laboratoryrecieptid],[patientid],[patientname],[doctorname],[departmentname],[laboratoryselectedservices],[laboratorycharges],[totalcharges])values('"+textBox_laboratory_reciept_id.Text+"','"+textBox_patient_id.Text+"','"+textBox_patient_name.Text+"','"+textBox_doctor_name.Text+"','"+textBox_department_name.Text+"','"+ listBox_selected_services.SelectedItem.Text+"','"+listBox_lab_charges.SelectedItem.Text+"','"+textBox_total_charges.Text+"')",connection.My_Get());
sumaira manzoor hussain khanRank #8,900 · 214 reputationPosted Aug 6, 2010, 6:28 AM EDT
your code generate this type of error .
Error 1 'object' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) D:\hospital management system\hospital management\hospital management\laboratory.cs 58 420 hospital management
Satyapriya NayakRank #47 · 31.5K reputationPosted Aug 6, 2010, 8:39 AM EDT
The application i wrote is webapplication not windows app.So check it out your app is win or web.
Thanks
Satyapriya NayakRank #47 · 31.5K reputationPosted Aug 6, 2010, 9:39 AM EDT
listBox_selected_services.Text change it to '"+listBox_selected_services.Text+"'
listBox_lab_charges.Text change it to '"+listBox_lab_charges.Text+"'
Change it in your query and test it ......
Thanks
sumaira manzoor hussain khanRank #8,900 · 214 reputationPosted Aug 6, 2010, 9:19 PM EDT
i add '"+listBox_selected_services.Text+"' and '"+listBox_lab_charges.Text+"' in my query . but there is not effect. the another thing is , i am using c-sharp express edition and my project is form based.
my query generate this type of error .
Error 1 'object' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Satyapriya NayakRank #47 · 31.5K reputationPosted Aug 7, 2010, 12:22 AM EDT
Can you attach your application i want to check it over here in my system.
Thanks
sumaira manzoor hussain khanRank #8,900 · 214 reputationPosted Aug 7, 2010, 12:25 AM EDT
my application is very heavy .
sumaira manzoor hussain khanRank #8,900 · 214 reputationPosted Aug 7, 2010, 12:31 AM EDT
the error exist in the insert query of laboratory module .
sumaira manzoor hussain khanRank #8,900 · 214 reputationPosted Aug 7, 2010, 12:33 AM EDT
ok. i have been sent my application to you .
thanks
theLizardRank #1,079 · 1.8K reputationPosted Aug 7, 2010, 2:16 AM EDT
listBox_lab_charges.SelectedValue.ToString()
Satyapriya NayakRank #47 · 31.5K reputationPosted Aug 7, 2010, 9:09 AM EDT
Change it in you ADD Button and try this .It will work sure....
private void button_ADD_Click(object sender, EventArgs e)
{
listBox_selected_services.SelectedIndex = 0;
listBox_lab_charges.SelectedIndex = 0;
MY_SQL_NEW_QUR.Access("insert into laboratory([laboratoryrecieptid],[patientid],[patientname],[doctorname],[departmentname],[laboratoryselectedservices],[laboratorycharges],[totalcharges])values('" + textBox_laboratory_reciept_id.Text + "','" + textBox_patient_id.Text + "','" + textBox_patient_name.Text + "','" + textBox_doctor_name.Text + "','" + textBox_department_name.Text + "','" + listBox_selected_services.SelectedItem.ToString() + "','" + listBox_lab_charges.SelectedItem.ToString() + "','" + textBox_total_charges.Text + "')",connection.My_Get());
}
Thanks
Satyapriya NayakRank #47 · 31.5K reputationPosted Aug 7, 2010, 7:54 PM EDT
Is it working now!.Iam attaching a sample application which i did it.I used Ms-access db which is located in bin folder.Check it out.
Thanks