|
do you have empty catch{} blocks ??
When you get mad...THINK twice that the only advice
Tamimi - Code
|
|
|
|
|
Try to use Stored Procedures and verify it
|
|
|
|
|
you have read just inserting code on particular event
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
namespace HotelProject
{
public partial class NewEmployee : Form
{
SqlConnection con;
SqlCommandBuilder cmdb;
SqlDataAdapter da;
DataSet ds;
public NewEmployee()
{
con = new SqlConnection("Data source=JBB-F906306D8CC\\SQLEXPRESS;Initial Catalog=Hotel;Integrated Security=SSPI");
InitializeComponent();
}
private void btnBrowseImagePath_Click(object sender, EventArgs e)
{
OpenFileDialog op = new OpenFileDialog();
if (op.ShowDialog() == DialogResult.OK)
{
txtBrowseImagePath.Text = op.FileName;
}
}
private void btnSubmitRecord_Click(object sender, EventArgs e)
{
con.Open();
da = new SqlDataAdapter("Select * From EmployeeDetails", con);
cmdb = new SqlCommandBuilder(da);
ds = new DataSet("EmployeeDetails");
if (txtBrowseImagePath.Text != "")
{
FileStream fs = new FileStream(txtBrowseImagePath.Text, FileMode.OpenOrCreate, FileAccess.Read);
byte[] rawdata = new byte[fs.Length];
fs.Read(rawdata, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
da.Fill(ds, "EmployeeDetails");
DataRow dr = ds.Tables["EmployeeDetails"].NewRow();
dr["FullName"] = txtFullName.Text;
dr["FatherName"] = txtFatherName.Text;
dr["DateOfBirth"] = maskedTxtDateofBirth.Text;
dr["Gender"] = cmbgender.SelectedItem.ToString();
dr["Address"] = txtAddress.Text;
dr["City"] = txtCity.Text;
dr["Country"] = cmbCountry.SelectedItem.ToString();
dr["PhoneNo"] = txtPhone.Text;
dr["EMailID"] = txtEMailId.Text;
dr["LicenceNo"] = txtLicence.Text;
dr["EmployeeHotelId"] = txtEhotelid.Text;
dr["DepartmentName"] = cmbDepartmentName.SelectedItem.ToString();
dr["Designation"] = cmbDesignation.SelectedItem.ToString();
dr["Qualification"] = cmbQualification.SelectedItem.ToString();
dr["SalaryPerMonth"] = txtSalary.Text;
dr["HireDate"] = maskedtxtHireDate.Text;
dr["UserName"] = txtUserName.Text;
dr["Password"] = txtPassword.Text;
dr["Picture"] = rawdata;
ds.Tables["EmployeeDetails"].Rows.Add(dr);
da.Update(ds, "EmployeeDetails");
con.Close();
MessageBox.Show("Inserted");
}
else
{
MessageBox.Show("Not Inserted");
}
}
private void btnReset_Click(object sender, EventArgs e)
{
txtFullName.Text = "";
txtFatherName.Text= "";
maskedTxtDateofBirth.Text= "";
cmbgender.Text= "";
txtAddress.Text= "";
txtCity.Text= "";
cmbCountry.Text= "";
txtPhone.Text= "";
txtEMailId.Text = "";
txtLicence.Text = "";
txtEhotelid.Text= "";
cmbDepartmentName.Text= "";
cmbDesignation.Text = "";
cmbQualification.Text = "";
txtSalary.Text= "";
maskedtxtHireDate.Text= "";
txtUserName.Text= "";
txtPassword.Text= "";
txtBrowseImagePath.Text = "";
}
private void btnUpdate_Click(object sender, EventArgs e)
{
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void NewEmployee_Load(object sender, EventArgs e)
{
txtBrowseImagePath.Enabled = false;
txtFullName.Focus();
}
private void txtFullName_Validating(object sender, CancelEventArgs e)
{
if (txtFullName.Text == "")
{
MessageBox.Show("You cannot leave it blank");
txtFullName.Focus();
}
else
{
txtFatherName.Focus();
}
}
private void txtFullName_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) == true)
{
MessageBox.Show("Insert character only");
txtFullName.Text = "";
}
}
private void txtFatherName_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) == true)
{
MessageBox.Show("Insert character only");
txtFatherName.Text = "";
}
}
private void txtFatherName_Validating(object sender, CancelEventArgs e)
{
if (txtFatherName.Text == "")
{
MessageBox.Show("You cannot leave it blank");
txtFatherName.Focus();
}
else
{
maskedTxtDateofBirth.Focus();
}
}
private void maskedTxtDateofBirth_Validating(object sender, CancelEventArgs e)
{
if (maskedTxtDateofBirth.Text == "")
{
MessageBox.Show("You cannot leave it blank");
maskedTxtDateofBirth.Focus();
}
else
{
cmbgender.Focus();
}
}
private void cmbgender_Validating(object sender, CancelEventArgs e)
{
if (cmbgender.SelectedItem==null)
{
MessageBox.Show("You cannot leave it blank");
cmbgender.Focus();
}
else
{
txtAddress.Focus();
}
}
private void txtAddress_Validating(object sender, CancelEventArgs e)
{
if (txtAddress.Text=="")
{
MessageBox.Show("You cannot leave it blank");
txtAddress.Focus();
}
else
{
txtCity.Focus();
}
}
private void txtCity_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) == true)
{
MessageBox.Show("Insert character only");
txtCity.Focus();
}
}
private void txtCity_Validating(object sender, CancelEventArgs e)
{
if (txtCity.Text == "")
{
MessageBox.Show("You cannot leave it blank");
txtCity.Focus();
}
else
{
cmbCountry.Focus();
}
}
private void cmbCountry_Validating(object sender, CancelEventArgs e)
{
if (cmbCountry.SelectedItem==null)
{
MessageBox.Show("You cannot leave it blank");
cmbCountry.Focus();
}
else
{
txtPhone.Focus();
}
}
private void txtPhone_Validating(object sender, CancelEventArgs e)
{
if (txtPhone.Text == "")
{
MessageBox.Show("You cannot leave it blank");
txtPhone.Focus();
}
else
{
txtEMailId.Focus();
}
}
private void txtPhone_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsLetter(e.KeyChar) == true)
{
MessageBox.Show("Insert Integer only");
txtPhone.Focus();
}
}
private void txtEMailId_Validating(object sender, CancelEventArgs e)
{
if (txtEMailId.Text == "")
{
MessageBox.Show("You cannot leave it blank");
txtEMailId.Focus();
}
else
{
txtLicence.Focus();
}
}
private void txtLicence_Validating(object sender, CancelEventArgs e)
{
if (txtLicence.Text == "")
{
MessageBox.Show("You cannot leave it blank");
txtLicence.Focus();
}
else
{
txtEhotelid.Focus();
}
}
private void txtEhotelid_Validating(object sender, CancelEventArgs e)
{
cmbDepartmentName.Focus();
}
private void cmbDepartmentName_Validating(object sender, CancelEventArgs e)
{
cmbDesignation.Focus();
}
private void cmbDesignation_Validating(object sender, CancelEventArgs e)
{
cmbQualification.Focus();
}
private void cmbQualification_Validating(object sender, CancelEventArgs e)
{
txtSalary.Focus();
}
private void txtSalary_Validating(object sender, CancelEventArgs e)
{
if (txtSalary.Text == "")
{
MessageBox.Show("You cannot leave it blank");
txtSalary.Focus();
}
else
{
maskedtxtHireDate.Focus();
}
}
private void txtSalary_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsLetter(e.KeyChar) == true)
{
MessageBox.Show("Insert Integer only");
txtSalary.Focus();
}
}
private void maskedtxtHireDate_Validating(object sender, CancelEventArgs e)
{
if (maskedtxtHireDate.Text == "")
{
MessageBox.Show("You cannot leave it blank");
maskedtxtHireDate.Focus();
}
else
{
txtUserName.Focus();
}
}
private void txtUserName_Validating(object sender, CancelEventArgs e)
{
if (txtUserName.Text == "")
{
MessageBox.Show("You cannot leave it blank");
txtUserName.Focus();
}
else
{
txtPassword.Focus();
}
}
private void txtPassword_Validating(object sender, CancelEventArgs e)
{
if (txtPassword.Text == "")
{
MessageBox.Show("You cannot leave it blank");
txtPassword.Focus();
}
else
{
btnBrowseImagePath.Focus();
}
}
}
}
|
|
|
|
|
I created Windows Service in C#.net
In this Windows Service I successfully connect to local sql server 2000 install in My PC.Then I retrive data from local sql server 2000 and fill that data into one dataset.Now I Want to connect to remote sql server 2000 to insert that data into database of that sql server 2000.
|
|
|
|
|
Seems like changing the connectionstring is enough to change database. Have you changed your connectionstring to connect another database. Is it possible for you ti share the code.
|
|
|
|
|
You can keep the connection strings in app.config file under the onnectionstrings section and read it using ConfigurationManager.ConnectionStrings
|
|
|
|
|
Hi.
I've created a service and installed it with following code :
public static void InstallService(string ExeFilename)
{
System.Configuration.Install.AssemblyInstaller Installer = new System.Configuration.Install.AssemblyInstaller(ExeFilename, new string[] { });
Installer.UseNewContext = true;
Installer.Install(null);
Installer.Commit(null);
}
I wanna start it after install, could you please guide me how I can do it ?
Thanks.
|
|
|
|
|
|
|
I am creating a custom control derived from ComboBox. I add some items to custom control in constructor of control.
// this code is sample
public MyCustomControl
{
this.Items.Add("test1");
this.Items.Add("test2");
}
When I drag this custom control to my form, designer auto-generate the code:
// this code in Form1.Designer.cs
this.mycustomControls.Items.AddRange(new object[] {
"test1",
"test2"});
When this custom control display on Form1, will have 4 items:
test1
test2
test1
test2
This problem cause duplication.
Please help me how to solve this problem, I don't want designer auto-generate these codes. Thanks.
|
|
|
|
|
can anyone explain me that how to show a form from windows service. i search google but found no solution. please explain anyone.
Thanks in advance
tbhattacharjee
|
|
|
|
|
The Question is how do you Display a Form ?
Form1 frm1 = new Form1();
frm1.Show();
i have not been doing win apps for a while now , but that is how its done.
My point is that need to create that form first and show it later.
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Tridip Bhattacharjee wrote: How to show a form from windows service?
Windows services don't interact with the user using UI.In fact they are "background" processes and it's not not safe to control the UI outside of the default drawing pool.If you need to control the service programatically
define your own custom commands and send them to the service using ServiceController.ExecuteCommand method.See this sample.And if you need to report for some errors use the event log.
Life is a stage and we are all actors!
|
|
|
|
|
In service properties at Log On tab "Allow Service to interact with desktop" should be checked.
|
|
|
|
|
Hello Friends
I have a TreeView which has many nodes which are are being created dynamically.
I have set a check box against each node of that TreeView. Now My Problem is I need to work with it's Click event. But how can I hold it.?
Here's The code where I do this.
private void BuildTree(List<ParentChild> liParentChild)
{
List<ParentChild> liParent = liParentChild.FindAll(delegate(ParentChild oParentChild) { return oParentChild.ParentID == 0; });
foreach (ParentChild currentParent in liParent)
{
TreeViewItem currentParentNode = new TreeViewItem();
currentParentNode.Tag = currentParent.ID;
string folderImagePath=@"C:\Documents and Settings\Sharif\My Documents\Visual Studio 2008\Projects\TreeView\TreeView\Images\FolderOne.jpg";
// string lowerLevelImagePath=@"C:\Documents and Settings\Sharif\My Documents\Visual Studio 2008\Projects\TreeView\TreeView\Images\FoldeTow.jpg";
string fileImagePath = @"C:\Documents and Settings\Sharif\My Documents\Visual Studio 2008\Projects\TreeView\TreeView\Images\File.jpg";
#region image and font style
StackPanel oStackPanel = new StackPanel();
oStackPanel.Orientation = Orientation.Horizontal;
CheckBox oCheckBox = new CheckBox();
oCheckBox.Name = "cb_" + currentParent.ID;
//oCheckBox.IsEnabled = false;
oStackPanel.Children.Add(oCheckBox);
oStackPanel.Children.Add(CreateIcon(folderImagePath));
TextBlock tb = new TextBlock();
tb.Text = currentParent.Name;
oStackPanel.Children.Add(tb);
currentParentNode.Header = oStackPanel;
#endregion
AddTreeChild(currentParentNode, liParentChild, currentParent,1,folderImagePath,fileImagePath);
tvParentChild.Items.Add(currentParentNode);
//ExpandAll(tvParentChild);
//CollapseAll(tvParentChild);
}
}
private void AddTreeChild(TreeViewItem currentParentNode,List<ParentChild> liPC,ParentChild currParent,int level,string folderImagePath,string fileImagePath)
{
int currntLevel = level + 1;
List<ParentChild> liChild = liPC.FindAll(delegate(ParentChild oParentChild) { return oParentChild.ParentID == currParent.ID; });
foreach (ParentChild currentChild in liChild)
{
TreeViewItem currentChildNode = new TreeViewItem();
StackPanel oStackPanel = new StackPanel();
oStackPanel.Orientation = Orientation.Horizontal;
currentChildNode.Tag = currentChild.ID;
#region font style and image
string sourcePath;
if(IsLeaf(currentChild.ID,liPC))
sourcePath = fileImagePath;
else
sourcePath = folderImagePath;
if (currntLevel % 2 == 0)
{
//currentChildNode.FontStyle = System.Windows.FontStyles.Italic;
currentChildNode.Foreground = Brushes.Brown;
//currentChildNode.Background = Brushes.White;
}
else
{
//currentChildNode.FontStyle = System.Windows.FontStyles.Normal;
currentChildNode.Foreground = Brushes.Black;
//currentChildNode.Background = Brushes.White;
}
CheckBox oCheckBox = new CheckBox();
oCheckBox.Name = "cb_" + currentChild.ID;
// oCheckBox.IsEnabled = false;
oStackPanel.Children.Add(oCheckBox);
oStackPanel.Children.Add(CreateIcon(sourcePath));
TextBlock tb = new TextBlock();
tb.Text = currentChild.Name;
oStackPanel.Children.Add(tb);
currentChildNode.Header = oStackPanel;
#endregion
AddTreeChild(currentChildNode, liPC, currentChild,currntLevel,folderImagePath,fileImagePath);
currentParentNode.Items.Add(currentChildNode);
}
}
|
|
|
|
|
1. Use pre tags when posting code. It looks more readable.
2. If you set the CheckBoxes property of the treeview to true, it will show checkboxes before each node. Then you can handle the NodeMouseClick event and capture the click.
3. If you still go will the current apprach, handle the CheckChanged event for each checkbox you add.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Hello All,
Is there anyway in which i can create a word document programmatically without using Office Interop or third-party libraries.
|
|
|
|
|
Yes - you can rewrite word, or if you want to only support the new version of Word, you can learn it's XML format and write something that uses that.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I dont want to re-write into a word document..i want to create a new word document..So is there any way??
|
|
|
|
|
|
I am getting the below error
WCF - HTTP Post The remote server returned an error: (400) Bad Request
client & sever code below
--------------------------------------------
ServiceContract]
[WebInvoke(UriTemplate = "", BodyStyle = WebMessageBodyStyle.Bare, Method = "POST")]
Stream SavePerson(Stream input);
-----------------------------
public Stream SavePerson(Stream input)
{
StreamReader streamReader = new StreamReader(input);
string rawString = streamReader.ReadToEnd();
streamReader.Dispose();
// try to store it in xml file
// I want to store the input stream to xml file
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(rawString);
xmlDoc.Save("D:\\a.xml");
//
Encoding encoding = Encoding.GetEncoding("ISO-8859-1");
WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
byte[] returnBytes = encoding.GetBytes(rawString);
return new MemoryStream(returnBytes);
}
-------------------------
Client Post
string postData = GetXmlString("d:\\test\\dirdownload.xml"); // user function
WebRequest request = WebRequest.Create("http://abc.xyv.com/mytest/myservice.svc");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
Response.Write (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Response.Write(responseFromServer);
// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();
---------------------------------------------------------
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(rawString);
xmlDoc.Save("D:\\a.xml");
how to save the request input stream to xml file ?
Please advise
|
|
|
|
|
You should post this in the WCF Section here http://www.codeproject.com/Forums/1004114/WPF-WCF-WF.aspx[^]
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
When I call the webservice method from my class synchronously or assynchronously i am receiving the following error:
(System.NullReferenceException: Object reference not set to an instance)
I am being able to call the loadWindow webservice method without any problem but when i pass the dataset as parameter in the saveWindow im receiving the error above. Any solution will be appreciated.
private void SaveData()
{
try
{
SYS_WS sysws = new SYS_WS();
sysws.SaveWindowCompleted +=new SaveWindowCompletedEventHandler(sysws_SaveWindowCompleted);
sysws.SaveWindowAsync((SYSDataset)dsSystem.GetChanges());
}
catch (Exception ex)
{
throw (ex);
}
}
private void sysws_SaveWindowCompleted(object sender,
SaveWindowCompletedEventArgs e)
{
try
{
if (e.Error != null)
{
return;
}
this.dsSystem.AcceptChanges();
}
catch (Exception ex)
{
throw ex;
}
}
[WebMethod(EnableSession = true)]
public bool SaveWindow(SYSDataset ds)
{
try
{
WindowController cont = new WindowController();
cont.SaveWindows(ds);
return true;
}
catch (Exception ex)
{
throw (ex);
}
}
[WebMethod(EnableSession = true)]
public SYSDataset LoadWindow(string WindowID)
{
WindowController cont = new WindowController();
return cont.LoadWindow(WindowID);
}
---- Stack Trace ----
RTR.SYS_V.Setup.frmWindow.SaveData()
frmWindow.cs: line 0091, col 17, IL 0079
RTR.SYS_V.Setup.frmWindow.btnSave_Click(sender As Object, e As EventArgs)
frmWindow.cs: line 0202, col 13, IL 0001
System.Windows.Forms.Control.OnClick(e As EventArgs)
MAIN.EXE: N 00111
System.Windows.Forms.Button.OnClick(e As EventArgs)
MAIN.EXE: N 00073
System.Windows.Forms.Button.OnMouseUp(mevent As MouseEventArgs)
MAIN.EXE: N 00171
System.Windows.Forms.Control.WmMouseUp(m As Message&, button As MouseButtons, clicks As Int32)
MAIN.EXE: N 00654
System.Windows.Forms.Control.WndProc(m As Message&)
MAIN.EXE: N 8788613
System.Windows.Forms.ButtonBase.WndProc(m As Message&)
MAIN.EXE: N 8807204
System.Windows.Forms.Button.WndProc(m As Message&)
MAIN.EXE: N 00031
System.Windows.Forms.ControlNativeWindow.OnMessage(m As Message&)
MAIN.EXE: N 00015
System.Windows.Forms.ControlNativeWindow.WndProc(m As Message&)
MAIN.EXE: N 00048
System.Windows.Forms.NativeWindow.Callback(hWnd As IntPtr, msg As Int32, wparam As IntPtr, lparam As IntPtr)
MAIN.EXE: N 00089
modified on Tuesday, September 1, 2009 2:18 AM
|
|
|
|
|
There are a number of errors in your post (please read the guidelines).
Your title is not acceptable - it is not urgent to anyone but yourself
Your posted code is not inside pre tag and is difficult to read.
You have not indicated where you get the error (what line)
You did describe the error so I can tell you there is an object that is declared but not initialised. Try debugging through the code to identify the line, look for an object that is 'null' where you expect it to have a value.
|
|
|
|
|
hi sir,
i remodified the document..concerning to the code i debugged i am loading the record and then modify data and save.
i checked the rows.count its 1 dataset is not null.
The line that im receiving the error is before calling the save webservice method.
SYS_WS sysws = new SYS_WS();
-->sysws.SaveWindowCompleted +=new SaveWindowCompletedEventHandler(sysws_SaveWindowCompleted);
<br />
Soap exception is thrown :<br />
soap System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
thanks for your help
|
|
|
|