|
|
O MGW FT
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
|
|
hi coders
i have a problem about my codes
let me tell the scenario first...i have two Forms(frm1 and frm2)...i opened frm2 by clicking a button on frm1..there is no problem till here...i want to save informations by filling the blanks on frm2 and save it but when i click save button there is nothing happen..here are my codes.. i couldnt see anything wrong in my connection or in my insert command...i need help about it
try
{
con = new SqlConnection("data source=Erdal2\\SQLEXPRESS;initial catalog=Medya;integrated security=true");
cmd = new SqlCommand("insert into Rehber (ad,soyad,firma,sektor,grup,cep_no,is_no,ev_no,fax,mail,web,msn,skype,dgm_tarih,adres,ilce,sehir,vergi_no,vrgi_daire) values (@ad,@soyad,@firma,@sektor,@grup,@cep_no,@is_no,@ev_no,@fax,@mail,@web,@msn,@skype,@dgm_tarih,@adres,@ilce,@sehir,@vergi_no,@vrgi_daire)", con);
con.Open();
cmd.Parameters.Add("@ad", SqlDbType.NVarChar).Value = txtAd.Text;
cmd.Parameters.Add("@soyad", SqlDbType.NVarChar).Value = txtSoyad.Text;
cmd.Parameters.Add("@firma", SqlDbType.NVarChar).Value = cmbFirma.SelectedItem;
cmd.Parameters.Add("@sektor", SqlDbType.NVarChar).Value = cmbSektor.SelectedItem;
cmd.Parameters.Add("@grup", SqlDbType.NVarChar).Value = txtGrup.Text;
cmd.Parameters.Add("@cep_no", SqlDbType.NVarChar).Value = txtCep.Text;
cmd.Parameters.Add("@is_no", SqlDbType.NVarChar).Value = txtisTlf.Text;
cmd.Parameters.Add("@ev_no", SqlDbType.NVarChar).Value = txtEvTlf.Text;
cmd.Parameters.Add("@fax", SqlDbType.NVarChar).Value = txtFax.Text;
cmd.Parameters.Add("@mail", SqlDbType.NVarChar).Value = txtMail.Text;
cmd.Parameters.Add("@web", SqlDbType.NVarChar).Value = txtURL.Text;
cmd.Parameters.Add("@msn", SqlDbType.NVarChar).Value = txtMSn.Text;
cmd.Parameters.Add("@skype", SqlDbType.NVarChar).Value = txtSkype.Text;
cmd.Parameters.Add("@dgm_tarih", SqlDbType.SmallDateTime).Value = dateTimePicker1.Value;
cmd.Parameters.Add("@adres", SqlDbType.NVarChar).Value = txtAdres.Text;
cmd.Parameters.Add("@ilce", SqlDbType.NVarChar).Value = txtIlce.Text;
cmd.Parameters.Add("@sehir", SqlDbType.NVarChar).Value = txtSehir.Text;
cmd.Parameters.Add("@vergi_no", SqlDbType.NVarChar).Value = txtVergiNo.Text;
cmd.Parameters.Add("@vrgi_daire", SqlDbType.NVarChar).Value = txtVergiDaire.Text;
if ((txtAd.Text != "") || (txtSoyad.Text != ""))
{
if (cmd.ExecuteNonQuery() == 1)
MessageBox.Show("Done", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
else
MessageBox.Show("Error during saving processes","Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
MessageBox.Show("There must be name and surname entered","warning",MessageBoxButtons.OK,MessageBoxIcon.Error);
i declared con and cmd as global variables...
|
|
|
|
|
If nothing at all is happening, then either it is not executing any of your code - place a breakpoint or MessageBox.Show before the "try" to check that - or it has an error and is going to your catch block - which you haven't shown.
BTW:
if ((txtAd.Text != "") || (txtSoyad.Text != "")) does not check that both name and surname are provided - you need "&&" not "||". Your error message implies both are required.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
hii man thanks for your reply
i tried to understand about my mistake by using breakpoint
it doesnt drop in if block..i mean the block below
if ((txtAd.Text != "") && (txtSoyad.Text != ""))
{
if (cmd.ExecuteNonQuery() == 1)
MessageBox.Show("Ekleme İşlemi Tamamlandı", "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Warning);
else
MessageBox.Show("Ekleme Sırasında Hata Oluştu","Dikkat", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
MessageBox.Show("İsim ve Soyisim Giriniz","Dikkat",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
it leaves the if control when it comes to ExecuteNonQuery() line and goes catch block.. here is my catch and finally block
catch (Exception)
{
if (((txtisTlf.Text.Length) + (txtKod.Text.Length)) > 20 || ((txtCep.Text.Length) + (txtCepKod.Text.Length)) > 20 || ((txtEvKod.Text.Length) + (txtEvTlf.Text.Length)) > 20 ||(txtFax.Text.Length) > 20)
MessageBox.Show("İş Telefonu,Cep Telefonu,Ev Telefonu,Fax No Alanları 20 Karakterden Fazla Olamaz", "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
con.Close();
}
|
|
|
|
|
Replace the "catch (Exception)" with "catch (Exception ex)" and have a look at the ex message and so forth. It will be telling you there is an error in your SQL syntax and will probably say "in SQL syntax near ..." where the ... bit gives you a clue where the problem is.
If that doesn't make is obvious, then cut down the insert statement until either it works or has only one value left - in which case the problem will be your connection string.
BTW: Parameters.Add(...).Value has been superceeded by Parameters.AddWithValue(name, value) - it won't make any difference at this point, but it's worth using the up-to-date stuff if you can.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
hi man
again me
i wrote ex as u said before and i have such a warning as an exception...
"The parameterized(@ad nvarchar(6),@soyad nvarchar(6),@firma nvarchar(4000))insert" expects parameter @firma,which was not supplied.and i have such codes to add this datas
cmd.Parameters.AddWithValue("@ad", txtAd.Text);
cmd.Parameters.AddWithValue("@soyad", txtSoyad.Text);
cmd.Parameters.AddWithValue("@firma", cmbFirma.SelectedItem);
and i keep that areas in my database like that
ad nvarchar(50),
soyad nvarchar(50),
firma nvarchar(60)
so i didnt get the problem i have now
|
|
|
|
|
I take it that you mean you have a field in your DB called "firma" which is declared as "nvarchar(60)", but your insert statement is still not working, and complains that parameter "@firma" is not supplied?
In which case, I suspect that cmbFirma.SelectedItem is a ComboBox and you have not selected anything in it? In which case "cmbFirma.SelectedItem" will return null, and this may be your problem - breakpoint the insert and check.
Good luck (and happy new year)!
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Dear Members,
kindly tell me the problem how to resolve it,i have to retrieve an image file from another network pc or remote pc,i m confused about it,how to work on it either have to work by mapping a network drive,or have a windows service for this purpose...any suggestion plzz
The language platform is C#
Regards
|
|
|
|
|
I'm confused by your question.
Am I right in saying that you want to copy a file from another location on the network to use it?
I would simply suggest mapping a drive to that location. That location would have to be shared though.
Then you just use <codefile.copy(sourcefilepath, destinationfilepath);=""> from System.IO; .
I hope this helps, or even makes sense. I need more coffee....
oooo, the Jedi's will feel this one....
|
|
|
|
|
Try having a look for " Socket Server C#" & " Socket Client C#"
or you could use good old "Sneakernet". ????
This is a bad question.
|
|
|
|
|
i'm trying to serialize and deserialize an object using xmlSerializer .the serialization part is ok ,but in the deserialization part i don't get "amount" calculated as expected.
following is the code of the object i serialize.
[Serializable]
public class _object
{
public int itemCnt;
public string itemName;
public decimal unitPrice;
[NonSerialized]public decimal amount;
public _object(int _itemCnt,string _itemName,decimal _unitPrice)
{
itemCnt = _itemCnt;
itemName = _itemName;
unitPrice = _unitPrice;
}
protected _object(SerializationInfo info, StreamingContext context)
{
itemCnt = info.GetInt32("itemCnt");
itemName = info.GetString("itemName");
unitPrice = info.GetDecimal("unitPrice");
amount = info.GetDecimal("total");
}
[SecurityPermissionAttribute(SecurityAction.Demand,SerializationFormatter = true)]
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("itemCnt", itemCnt);
info.AddValue("itemName", itemName);
info.AddValue("unitPrice", unitPrice);
amount = itemCnt * unitPrice;
}
}
any idea why?
|
|
|
|
|
Are you setting the amount outside your class? I cannot see where it would be calculated.
prasadbuddhika wrote: [NonSerialized]public decimal amount;
If this is the case, when you are deserialzing your class, you will lose the Amount value as it is NonSerialized, so not stored when serialized...
oooo, the Jedi's will feel this one....
|
|
|
|
|
prasadbuddhika wrote: [NonSerialized]public decimal amount;
Amount is marked as 'non serializable'.
There are only 10 types of people in this world — those who understand binary, and those who don't. |
|
|
|
|
|
wish you all a happy new year..! thanx for your reply . i had made a mistake the constructor with the serialzationinfo and the streamcontext is the one which will be called at deserialization. so i had to calculate the amount in this . then the constructor will be changed to
protected _object(SerializationInfo info, StreamingContext context)
{
itemCnt = info.GetInt32("itemCnt");
itemName = info.GetString("itemName");
unitPrice = info.GetDecimal("unitPrice");
amount = itemCnt * unitPrice;
}
but the problem is still remaining...the itemCnt,itemName and unitPrice are getting accurately , only the calculation is not taking place..
|
|
|
|
|
Hi,
I tried created a windows service which does a file transfer from the folder its watching whenever a new file being created in it.I am getting an exception saying "The path is not of a legal form." on trying to start the service. An the path the exception refering to is the path that i set to the FileSystemWatch. Path property. I dont understand why it happens. The path is "D:\Test". The folder has all the permission to access.
Can anyone help me out.
|
|
|
|
|
When setting your path did you use an @ ?
string path = @"D:\Test";
Without that, that \T will likely get converted to a tab which would not be a legal form.
Regards,
Rob Philpott.
|
|
|
|
|
Without the code it is difficult to help, can post it please? Remember to use <pre> tags !
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
Service1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Configuration;
namespace FileTransfer
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
try
{
FileTransferWatcher.Created += new System.IO.FileSystemEventHandler(FileTransferWatcher_Created);
}
catch (Exception ex)
{
EventLog.WriteEntry("Message : " + ex.Message);
}
}
void FileTransferWatcher_Created(object sender, System.IO.FileSystemEventArgs e)
{
System.IO.File.Copy(e.FullPath, @"D:\");
}
protected override void OnStop()
{
}
}
}
Service1.Designer.cs
namespace FileTransfer
{
partial class Service1
{
private System.ComponentModel.IContainer components;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
private void InitializeComponent()
{
this.FileTransferWatcher = new System.IO.FileSystemWatcher();
this.FileTransferWatcher.EnableRaisingEvents = true;
this.FileTransferWatcher.Path = "D:\\Test\\";
this.ServiceName = "FileTransfer";
}
#endregion
private System.IO.FileSystemWatcher FileTransferWatcher;
}
}
The bolder statement is were the exception is thrown.
|
|
|
|
|
You need to set
this.FileTransferWatcher.Path = "D:\\Test\\";
before this
FileTransferWatcher.EnableRaisingEvents = true;
As the inital path of a FileSystemWatcher is an empty string.
Also, as a side note, hardcoding the paths in magic strings isn't a good plan (though obviously the code posted is, by definition, unfinished). I'd also move out the FileWatcher/Transfer code into a separate class that deals with this and let the service just handle the service related stuff.
The other thing is, if you can, I'd run this as a console app and then convert it into a service later as debugging services is trickier.
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
Thanks Keefb!
I got the mistake i have done... Also as you said i should have started with as a console application.
|
|
|
|
|
This is just a guess, but does the directory exist? I've looked at the property's code through Reflector, and that's the only thing that will throw the exception.
By the way, your File.Copy will fail, because you haven't specified a source filename, just the parent directory.
|
|
|
|
|
Sorry, I try to understand what you are doing:
void FileTransferWatcher_Created(object sender, System.IO.FileSystemEventArgs e)
{
System.IO.File.Copy(e.FullPath, @"D:\");
}
/pre>
Are you copying a file to your observed directory when you register the handler?
|
|
|
|
|