System Error
SqlConnection myConn = new SqlConnection();
myConn.ConnectionString="Data Source=myIP,1433;Network Library=DBMSSOCN;Initial Catalog=gokhan;User ID=sa;Password=systems";
myConn.Open();
try
{
string StrSql = "INSERT into netonetable(netonename) VALUES myname";
SqlCommand myCommand = new SqlCommand(StrSql, myConn);
myCommand.ExecuteNonQuery();
}
finally
{
myConn.Close();
}
well at this table i have lots of columns which are not allowed to be nulls.Can this error happen bc of just trying to insert A value and the others being null?
[636 byte] By [
gokhan] at [2007-11-20 1:16:48]

# 1 Re: System Error
If you have columns which do not allow Null values and you are not passing anything to those columns then this query will surely error out.
# 2 Re: System Error
well i gave the values and it still gives the error.
it is probably about connection.
im trying to insert values to a database which is at another computer in the same room with myIP ip adress.sql server is running
gokhan at 2007-11-10 3:31:17 >

# 3 Re: System Error
Does it error out at myConn.Open line?
If so then the problem is with the connection string.
Or if it errors out at the ExecuteNonQuery line then the problem is with the SQL Query.
# 4 Re: System Error
string StrSql = "INSERT into netonetable VALUES (myname,myadress,myareacode,myphone,mykurumsal,myaramatik,myfatura,myvergi,mykimlik,mysicil,mysonay,myimza)";
here is where it gives the error.
AND
mvergi mykimlik mysicil mysonay myimza are defined as intS in my C# code but in the database these are defined as bits.
gokhan at 2007-11-10 3:33:25 >

# 5 Re: System Error
There is nothing wrong with the connection if it opens without any error. The problem is with your Query. If you want to add a row in the table then you should specify the column names too. And when you are trying to insert the values using the variables in your code then you need to put them like this string SQL = "Insert Into TABLE1(NAME, ADDRESS, AGE) Values ('" + myName + "','" + myAddress + "'," + myAge.ToString() + ")"; Where myName & myAddress are variables in the C# code defined as Strings and myAge is defined as Integer.
# 6 Re: System Error
to be sure i have done all the things typed as string in c# and all the columns as varchar(50).
it does not help.im sorry :(
here is the code
SqlConnection myConn = new SqlConnection();
myConn.ConnectionString="Data Source=myIP,1433;Network Library=DBMSSOCN;Initial Catalog=gokhan;User ID=sa;Password=";
myConn.Open();
try
{
string StrSql = "Insert Into netonetable(name,adress,area,phone,kurumsal,aramatik,fatura,vergi,kimlik,sicil,sonay,imza) VALUES (' " + myname + " ',' " + myadress + " ',' " + myareacode + "','" + myphone + " ', ' " +mykurumsal + " ', ' " + myaramatik + " ',' " + myfatura + " ',' " + myvergi + " ', ' " + mykimlik + " ',' " + mysicil + " ',' " + mysonay + " ', ' " +myimza + " ')";
SqlCommand myCommand = new SqlCommand(StrSql, myConn);
myCommand.ExecuteNonQuery();
}
finally
{
myConn.Close();
}
well all of them are stringS in code and varcharS(50) in the table
does not help :(
gokhan at 2007-11-10 3:35:18 >

# 7 Re: System Error
Can you show us the error message that it is showing?
# 8 Re: System Error
it gives the System.Data.SqlClient.SqlException exception.
Well thank you so much about the help.
im gonna try to fix this problem bc im angry about it :)
when i fix it and figure it out why it gives the error i will write down the error.
What i see is just System.Data.SqlClient.SqlException and it writes out system error.the application gets frozen too
gokhan at 2007-11-10 3:37:25 >

# 9 Re: System Error
That is kind of weird. Remove the Try block from your code and then try to execute it again, but execute it in the debug mode. If there is an error you will get atleast a little bit detailed message.
# 10 Re: System Error
i'll try this too.i hope this will help
Thanks for help very much.
gokhan at 2007-11-10 3:39:26 >
