Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Manual SQl Dont work Correctly

Author  Topic 

Lotus
Starting Member

14 Posts

Posted - 2007-11-10 : 08:07:28
Hello All Prg's
I need your help,
I use Database SQL server Express with C#
when I entred some data into DB by clciking on the table in server Explorer in Visual Studio 2005 IDE,
and then I make SQL in the code
as:
if (e.KeyCode == Keys.Return)
{
bool res;
int OldPlayerId = 0;
string ConnectionStr = Program.Member_Connect;
string sqlQuery = "select Player_ID from Player where Player_Code = '" + textBox1.Text + "'";
SqlConnection Sql_connection = new SqlConnection(ConnectionStr);
Sql_connection.Open();
SqlCommand command = new SqlCommand(sqlQuery, Sql_connection);
SqlDataReader dataReader = command.ExecuteReader();
if (dataReader.HasRows)
{
if (dataReader.Read())
OldPlayerId = dataReader.GetInt32(0);
else
MessageBox.Show("rtet");
}
else
{
res = false;
}
comboBox2.SelectedValue = textBox1.Text;
command.Dispose();
Sql_connection.Close();
Sql_connection.Dispose();
comboBox1.SelectedValue = OldPlayerId;
}
it work correctly on the old data that I entred them manualy, but when I enter new data from my project, this query don't give correct value, it still work correctly on old data,

I tried to take same data by combobox connected to view that contain same sql ,it work always.
but I need manualy Sql.
Please help me , I am very lating to delever my project...
please help me
thank you very mush

nr
SQLTeam MVY

12543 Posts

Posted - 2007-11-10 : 08:20:33
Have a look at the database and see what the difference is between the old data and new data.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Lotus
Starting Member

14 Posts

Posted - 2007-11-10 : 08:42:47
I know SQL but new in SQL Server,
tha database in tow case is same . i don't change it , but the problem in result in data(old data entred dirctly into database manualy in the Visual Studio 2005 Ide,new data entred by the project that I work with it),
I don't work with Cursors if you have semple tutorial give me blease..
thank you Mr.nr
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-11-10 : 19:10:03
quote:
Originally posted by Lotus

Hello All Prg's
I need your help,
I use Database SQL server Express with C#
when I entred some data into DB by clciking on the table in server Explorer in Visual Studio 2005 IDE,
and then I make SQL in the code
as:

it work correctly on the old data that I entred them manualy, but when I enter new data from my project, this query don't give correct value, it still work correctly on old data,

I tried to take same data by combobox connected to view that contain same sql ,it work always.
but I need manualy Sql.
Please help me , I am very lating to delever my project...
please help me
thank you very mush




If I follow this correctly:
1. Data used to be entered directly, by hand using the SQL IDE and then queried from your C# program (I think)
OR
You have attempted to make a C# program used to enter the data, instead of entering it manually in the IDE.
OR
The query worked on data entered manually, but now isn't working when queried from your project.


2. You reference that the query passed to the server:
 string sqlQuery = "select Player_ID from Player where Player_Code = '" + textBox1.Text + "'";

doesn't work the same way or is producing different data, but don't explain what the difference is or show sample data with desired results.

5. You say the data is different, but don't explain the data itself, or why/how it is different from what it should be.

6. You have promised to deliver a project, but are now late due to inexperience and are hoping that we can bail you out somehow.

I would start with comparing data entered manually against data entered from the program. Check the length of field values to make sure there aren't leading/trailing spaces.

I am not sure what manually SQL means.

Can you clarify? Post data that works, data that doesn't..
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-11-10 : 19:13:22
quote:
Originally posted by Lotus

I know SQL but new in SQL Server,
tha database in tow case is same . i don't change it , but the problem in result in data(old data entred dirctly into database manualy in the Visual Studio 2005 Ide,new data entred by the project that I work with it),
I don't work with Cursors if you have semple tutorial give me blease..
thank you Mr.nr



What does this have to do with cursors?
Go to Top of Page

Lotus
Starting Member

14 Posts

Posted - 2007-11-11 : 09:17:27
Dear dataguru1971...
I will Try To Explain my Problem slowly....Sorry I am not fluent in English..
when You connect the Database SQL server Express into IDE, you can take the Connection string by click on the
server Explorer->DB_Project.mdf -> proberties ->Connection string
I take it , and store it in Global Variable.
as Program.Member_Connect
ofcorse I change '\' by '/' and " by '
this connection string is work correctly.I tried it.
I need to know some data is already exsist or not.
I used this query
string sqlQuery = "select Player_ID from Player where Player_Code = '" + textBox1.Text + "'"; in code as display Above.
I Entered some data into the tables for test from IDE,by clicking on tables name at
server Explorer->DB_Project.mdf ->Tables->player.
when I run the progam .
this query return correct result when I ask about data that I Entred already.
then I entered from my program GUI data into the database and see it in the some data gride in my program.
It is OK to this moment...
but now when I use this query(same query above) it return correct result on the old data , but it does not see the new data here.




Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-11-11 : 09:23:10
So, you entered new data from your GUI and it doesn't end up in the actual database?

It seems you are entering data on the data grid in the GUI, but there is nothing telling that data to go to the server itself. Do you have any statements to Insert INTO the table from your code? It just sounds to me like you are not telling the data from the GUI data grid to be put into the server side table.
Go to Top of Page

Lotus
Starting Member

14 Posts

Posted - 2007-11-11 : 09:33:46
I want to send Snapshoot about my problem but I can't upload picture here,can i upload image???
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-11-11 : 09:39:07
It seems clear to me,
quote:

then I entered from my program GUI data into the database and see it in the some data gride in my program.


This sounds like you enter the data into the GUI and see it on the data grid

and:
quote:

but now when I use this query(same query above) it return correct result on the old data , but it does not see the new data here.



this says when you then query the actual database on the server, you don't see what you just entered. How are you getting the data from the GUI into the table? (note that just typing it into the GUI isn't enough by itself, from what you have already posted).
Go to Top of Page

Lotus
Starting Member

14 Posts

Posted - 2007-11-11 : 09:45:27
I use datagride for display the date while I enter the data from TextBox,
I now tride to Enter row data,and then I close the application
and reopen the application i found the new data is exsist correctly,
but also the query is work only on the old rows correcty..
I don't know why....
Go to Top of Page

Lotus
Starting Member

14 Posts

Posted - 2007-11-11 : 09:50:56
yes, I had transffer data into DB by the code:

this.playerBindingSource.EndEdit();
this.playerTableAdapter.Update(this.callerProject_DBDataSet.Player);

do you mean this???
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-11-11 : 10:04:31
I guess it isn't really clear to me what you are saying after all.

Simple yes or no:
When you enter data from your GUI, does it end up in the actual database?

If NO, then the problem is in the transfer of data to your database

If YES, then maybe if you are bringing the data set into your application, does your application re-query the databse to refresh the data grid source?
Go to Top of Page

Lotus
Starting Member

14 Posts

Posted - 2007-11-11 : 10:47:05
OH ..Thank my God,
And thank you my friend dataguru1971 ,
my problem is solved ..
the problem was :
when I run the Project in debug mode , It generate a new DB file in the ~\Debug\Bin directory
and it automaticly connect the Project into new DB file,
But I stored the connection string in string variable(the path into old DB)
so when add new row in DB automaticly transffer it into new DB but when I query manulay I ask to it to connect old DB file , so it return wrong result..
thank you again
I am sorry for wasting your Time....
thank you for interesting..
Lotus
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-11-11 : 10:51:40
You didn't waste my time at all. Glad you found an answer.
Go to Top of Page
   

- Advertisement -