Hi.i am trying to compare today 's date with a date from database.if it found like today 's date is available from database it should return something like eventname.here is my code string Today = DateTime.Now.ToShortTimeString().ToString(); SqlCommand cmdDisplay = new SqlCommand(); cmdDisplay.Connection = conn; cmdDisplay.CommandText = "SELECT EventName FROM Events WHERE EventDate = '"+ Today + "'"; SqlDataReader dr = cmdDisplay.ExecuteReader(); while(dr.Read()) { string EDate; EDate = dr["EventDate"].ToString(); if(EDate == Today) { txtEventName.Text =dr["EventName"].ToString(); } }
Mamphekgo
Posts
-
Compare dates -
Export data to datageridhi.i need to export data from datagrid to excel.can you please help me or give me link that i can refer from it
-
export data from datagrid to excel [modified]Hi everyone I am trying to export data from datagrid to excel but gives me this erro"Obect reference not set to instance of the object".here is my code.I am using windows C#. lblMessage.Text = ""; DataTable dtTransactions = dsTransactions.Tables["Transactions"].Copy(); int[] iColumns = {0,1,2,3,5,6}; RKLib.ExportData.Export objExport = new RKLib.ExportData.Export("Win"); objExport.ExportDetails(dtTransactions,iColumns,Export.ExportFormat.Excel,"C:\\TransactionsInfo.Excel"); lblMessage.Text = "Successfully exported to C:\\TransactionsInfo.Excel"; -- modified at 8:28 Thursday 31st August, 2006
-
Display a on the datagrid [modified]Hi.i did a project a that records a transactions that customer make daily something like Bank,so i want to display only transactions that were made by a specific customer using his account number on the datagrid.the problem is it doesn't display the record i that requested it to display only so i did something like this. public bool DisplayTrans(string CBarcode2) { try { conn1= new SqlConnection(ConString); cmdDisplay1= new SqlCommand(); daDisplay = new SqlDataAdapter(); dsDisplay = new DataSet(); cmdDisplay1.Connection = conn1; daDisplay.SelectCommand = cmdDisplay1; cmdDisplay1.CommandText = "SELECT CustomerName,ProductName,Price,EventName,BoughtDate,BoughtTime FROM Transactions WHERE Barcode2 =@Barcode2 "; SqlParameter Bar = new SqlParameter(); Bar.ParameterName = "@Barcode2"; Bar.Direction = System.Data.ParameterDirection.Input; Bar.Value = CBarcode2; cmdDisplay1.Parameters.Add(Bar); daDisplay.Fill(dsDisplay,"Transactions"); } catch(Exception ex) { MessageBox.Show(ex.Message); return false; } return true; -- modified at 5:31 Thursday 24th August, 2006
-
binding data with texboxesis this right way to bind data with texboxes when you use classes,i mean i need to display data on labels. private void btnGo_Click(object sender, System.EventArgs e) { try { SearchCustomers search = new SearchCustomers(); string Barcode1; string CustomerName="" ; string Barcode; string ProductName=""; string Price = ""; search.CustomerName = "jakes"; if(txtBarcode.Text.Length <4) { Barcode1 =txtBarcode.Text; lblCustomerName.Text = CustomerName; search.SeachCustomer( CustomerName, Barcode1); } else { Barcode = txtBarcode.Text; lblProductName.Text = ProductName; lblPrice.Text =Price; search.SeachProduct(Barcode, ProductName, Price);
-
Classes [modified]Hi. I have created a class that read data from the database and i want to display this data on labels. here is my class public void SeachProduct(string PBarcode,string PName,string PPrice) { Barcode = PBarcode; ProductName = PName; Price = PPrice; SqlConnection conn1 = new SqlConnection(); conn1.ConnectionString = "integrated security=SSPI;initial catalog=Phusa;server = za211149;persist security info=False"; conn1.Open(); try { SqlCommand cmdSearch1 = new SqlCommand(); cmdSearch1.Connection = conn1; cmdSearch1.CommandText = "SELECT ProductName,Price FROM Products WHERE Barcode=@Barcode"; SqlParameter Bar = new SqlParameter(); Bar.ParameterName = "@Barcode"; Bar.Direction = System.Data.ParameterDirection.Input; Bar.Value = Barcode; cmdSearch1.Parameters.Add(Bar); SqlParameter Nam1 = new SqlParameter(); Nam1.ParameterName="@ProductName"; Nam1.Direction = System.Data.ParameterDirection.Output; Nam1.Value =ProductName; cmdSearch1.Parameters.Add(Nam1); SqlParameter Pri= new SqlParameter(); Pri.ParameterName = "@Price"; Pri.Direction = System.Data.ParameterDirection.Output; Pri.Value = Price; cmdSearch1.Parameters.Add(Pri); SqlDataReader dr1 =cmdSearch1.ExecuteReader(); if(dr1.Read()==true) { //MessageBox.Show("Product found"); ProductName= dr1["ProductName"].ToString(); Price = dr1["Price"].ToString(); } else { MessageBox.Show("Product not found"); } } catch(Exception ex) { MessageBox.Show(ex.Message); } finally { conn1.Close(); } and here i am try to call so that it can display data on the labels my class on form SearchCustomers search = new SearchCustomers(); string Barcode; string ProductName=""; string Price = ""; Barcode = txtBarcode.Text; search.SeachProduct(Barcode,ProductName,Price); lblProductName.Text = ProductName; lblPrice.Text =Price; } -- modified at 4:03 Thursday 17th August, 2006
-
display data on textboxes from database using classes [modified]actually my code can see that there is data on the database because when i use messagebox to search if ever there is something ot the database it shows that it found the record.but data cannot display on the texboxes,here i am trying to call my class to display data. SearchCustomers search = new SearchCustomers(); string Barcode1; string CustomerName =""; string Barcode; string ProductName=""; string Price = ""; if(txtBarcode.Text.Length <4) { Barcode1 =txtBarcode.Text; CustomerName = lblCustomerName.Text; search.SeachCustomer(CustomerName,Barcode1); } else { Barcode = txtBarcode.Text; lblProductName.Text = ProductName; lblPrice.Text =Price.ToString(); search.SeachProduct(Barcode,ProductName,Price); }
-
display data on textboxes from database using classes [modified]Hi. i am still new on C#.i am trying to display data on the texboxes from database using classes but it doesn't display any data where as is there here is my class. public void SeachCustomer(string CName,string CNum) { CustomerName = CName; Barcode1 = CNum; SqlConnection conn = new SqlConnection(); conn.ConnectionString = "integrated security=SSPI;initial catalog=Phusa;server = za211149;persist security info=False"; conn.Open(); try { SqlCommand cmdSearch = new SqlCommand(); cmdSearch.Connection = conn; cmdSearch.CommandText = "SELECT CustomerName FROM Events WHERE Barcode1 =@Barcode1"; SqlParameter Bar = new SqlParameter(); Bar.ParameterName = "@Barcode1"; Bar.Direction = System.Data.ParameterDirection.Output; Bar.Value = Barcode1; cmdSearch.Parameters.Add(Bar); SqlParameter Nam = new SqlParameter(); Nam.ParameterName="@CustomerName"; Nam.Direction = System.Data.ParameterDirection.Output; Nam.Value =CustomerName; cmdSearch.Parameters.Add(Nam); SqlDataReader dr =cmdSearch.ExecuteReader(); while(dr.Read()==true) { CustomerName = dr["CustomerName"].ToString(); } } catch(Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } -- modified at 4:02 Wednesday 16th August, 2006
-
Object reference not set to instance of an objectyes i did.it gives me this error on the first line
-
Object reference not set to instance of an objecti am trying to run this code but it always gives me this error"Object reference not set to instance of an object" and here is my code try { DataAcces datc=new DataAcces(); this.txtID.DataBindings.Add("Text",datc.dsDisplay.Tables["Customers"],"CustomerID"); this.txtName.DataBindings.Add("Text",datc.dsDisplay.Tables["Customer"],"CustomerName"); this.txtSurname.DataBindings.Add("Text",datc.dsDisplay.Tables["Customers"],"CustomerSurname"); this.txtEmail.DataBindings.Add("Text",datc.dsDisplay.Tables["CustomerEmail"],"CustomerEmail"); } catch(Exception ex) { MessageBox.Show(ex.Message); }
-
Populate datasethi guys i am trying to populate dataset using classes but it gives me this error" Cannot create an instance of the abstract class or interface" and here is my code. public class DataAcces { public SqlConnection conn; //public SqlCommand cmdDisplay; public DataSet dsDisplay ; public DataAdapter daDisplay; private string ConString = "integrated security = SSPI;initial catalog = Phusa;server = za211149;persist security info = false"; public DataAcces() { // // TODO: Add constructor logic here // } public bool Connection() { try { conn = new SqlConnection(ConString); DataAdapter daDisplay = new DataAdapter("SELECT * FROM Customers",conn); dsDisplay = new DataSet(); daDisplay.Fill(dsDisplay); } catch(Exception ex) { MessageBox.Show(ex.Message); return false; } return true; }
-
Binding Datagrid with texboxesHi.i have created application that has datagrid and texboxes.my application load data on datagrid on form load so i want display the same data on the texboxes,when ever i select a record on datagrid the the data on the texboxes must change according to the record.
-
ClassesHi.i want to craete a class that will read data from database and display it on the texboxes.but it can not display it.so i did this try { SqlCommand cmdSearch = new SqlCommand(); cmdSearch.Connection = conn; cmdSearch.CommandText = "SELECT Name,Surname FROM Users WHERE UserName =@UserName"; SqlParameter Nam = new SqlParameter(); Nam.ParameterName = "@Name"; Nam.Direction = System.Data.ParameterDirection.Output; Nam.Value = Name; cmdSearch.Parameters.Add(Nam); SqlParameter Sur = new SqlParameter(); Sur.ParameterName="@Surname"; Sur.Direction = System.Data.ParameterDirection.Output; Sur.Value = Surname; cmdSearch.Parameters.Add(Sur); SqlParameter Use = new SqlParameter("@UserName",System.Data.SqlDbType.VarChar,50,UserName); Use.Value = UserName; cmdSearch.Parameters.Add(Use); SqlParameter Lev = new SqlParameter(); Lev.ParameterName="@Level"; Lev.Direction = System.Data.ParameterDirection.Output; Lev.Value = Surname; cmdSearch.Parameters.Add(Lev); SqlDataReader dr =cmdSearch.ExecuteReader(); if(dr.Read() == true) { MessageBox.Show("Record found"); } else { MessageBox.Show("Record not found"); } } catch(Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close();
-
radiobuttonHi i have created a form with two radiobuttons Administrator and user.i want to insert either of this radiobttons to database so the problem is it only insert user.my line of code is like this. Level= (rdbAdministrator.Checked)?"Administrator":"User";
-
update statements using classes [modified]Hi.i am try to write update statement using classes but it always gives me an error and use this on my form.i did something like this. public class Update { string empname = ""; public Update() { // // TODO: Add constructor logic here // } public void updateEmployee(string empname1) { empname = empname1; SqlConnection conn = new SqlConnection(); conn.ConnectionString = "integrated security=SSPI;initial catalog=Employee;server = za211149;persist security info=False"; conn.Open(); try { SqlCommand UpdateEmp = new SqlCommand(); UpdateEmp.Connection = conn; UpdateEmp.CommandText = "UPDATE jakes"; UpdateEmp.Parameters.Add(new SqlParameter("@empname",System.Data.SqlDbType.VarChar,50,empname)); UpdateEmp.Parameters["@empname"].Value = this.empname.ToString(); if(UpdateEmp.ExecuteNonQuery()==1) { MessageBox.Show("record updated"); } else { MessageBox.Show("record not updated"); } } catch { MessageBox.Show("o a gafa"); } finally { conn.Close(); } } -- modified at 9:03 Wednesday 19th July, 2006
-
Classes [modified]thanx.i got it right now
-
Classes [modified]Hi.i am C# beginner,i have created two folders for my project so other folder is for classes and the other one is for my forms so i am trying to use my classes from another folder but i can't see them.
-
need to insert name in the database using methodactually my code is like this. using System; using System.Data.SqlClient; using System.Data.SqlTypes; using System.Windows.Forms; namespace bb { /// /// Summary description for connection. /// public class connection1 { public string empname; public connection1() { // // TODO: Add constructor logic here // } public void InsertValues(string empname1) { SqlConnection conn = new SqlConnection(); conn.ConnectionString = "integrated security=SSPI;initial catalog=Employee;server = za211149;persist security info=False"; conn.Open(); try { SqlCommand cmdInsert = new SqlCommand(); cmdInsert.Connection = conn; empname = empname1; cmdInsert.CommandText = "INSERT INTO jakes VALUES(@empname)"; cmdInsert.Parameters.Add(new SqlParameter("@empname",System.Data.SqlDbType.VarChar,50,"empname")); cmdInsert.Parameters["@empname"].Value = empname.ToString(); if (cmdInsert.ExecuteNonQuery() !=0) { MessageBox.Show("Record inserted"); } else { MessageBox.Show("record not inserted"); } //return true; } catch(Exception E) { MessageBox.Show(E.ToString()); //return false; } finally { conn.Close(); } } } }
-
need to insert name in the database using methodhi.i am struggling to insert name in the database using method.it gives me this error "Use of unassigned local variable 'empname'" and my code is as follows. public void InsertValues(string empname1) { SqlConnection conn = new SqlConnection(); conn.ConnectionString = "integrated security=SSPI;initial catalog=Employee;server = za211149;persist security info=False"; conn.Open(); try { SqlCommand cmdInsert = new SqlCommand(); cmdInsert.Connection = conn; empname = empname1; cmdInsert.CommandText = "INSERT INTO jakes VALUES(@empname)"; cmdInsert.Parameters.Add(new SqlParameter("@empname",System.Data.SqlDbType.VarChar,50,"empname")); cmdInsert.Parameters["@empname"].Value = empname.ToString(); if (cmdInsert.ExecuteNonQuery() !=0) { MessageBox.Show("Record inserted"); } else { MessageBox.Show("record not inserted"); } //return true; } catch(Exception E) { MessageBox.Show(E.ToString()); //return false; } finally { conn.Close(); } }
-
Using classes on windows formsHi.i am still learning C# so i am trying to create a simple class for greeting message so i want to display this message on a label on form.please send me a sample and explanation.