-
September 12th, 2006, 07:21 AM
#1
System Error
Code:
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?
Last edited by gokhan; September 12th, 2006 at 08:14 AM.
-
September 12th, 2006, 07:54 AM
#2
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.
-
September 12th, 2006, 08:13 AM
#3
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
-
September 12th, 2006, 08:21 AM
#4
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.
-
September 12th, 2006, 08:28 AM
#5
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.
-
September 12th, 2006, 08:44 AM
#6
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
Code:
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.
-
September 12th, 2006, 09:24 AM
#7
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
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
Last edited by gokhan; September 12th, 2006 at 09:48 AM.
-
September 13th, 2006, 02:31 AM
#8
Re: System Error
Can you show us the error message that it is showing?
-
September 13th, 2006, 09:38 AM
#9
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
-
September 14th, 2006, 02:34 AM
#10
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.
-
September 14th, 2006, 07:55 AM
#11
Re: System Error
i'll try this too.i hope this will help
Thanks for help very much.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|