|
Using sq brackets did not solve this. This provided me also with the error "INSERT INTO statement contains an unknown field 'Date'" or something to that effect. In the end I just changed the field name... I believe that access is reading "Date" as an identifier rather than a field name where it expects a field name...?
°[Halo]°
Project Basilisk
|
|
|
|
|
Quite possibly. If this is on MS SQL, try using brackets [] around the field.
|
|
|
|
|
Doh.. replies didnt show up at first. Ignore redundant post.
|
|
|
|
|
Hi !
I want to search the field of "telephone":
table:MyTable ,
id_name[int],name[nvarchar],family[nvarchar],telephone[decimal]. id_name is a primary key .
when I want to search a telephone , for example:
telephone=3339964
I write in c#:
string mysearch;
mysearch="SELECT * From MyTable WHERE telephone=3339964"; Now , If the telephone is NULL (one don't enter his telephone) and I want to search this name and family,How can I write this SQL ?
mostafa hosseiny b.
|
|
|
|
|
So, you want a query that will search by telephone. If telephone is null you want to seach by name and family instead.
This is the query you want:
SELECT *
FROM MyTable
WHERE (telephone=@telephone AND @telephone IS NOT NULL)
OR ((family = @family AND name = @name) AND @telephone IS NULL)
And the C# code to go with it:
string mySearch = "SELECT * "+
"FROM MyTable "+
"WHERE (telephone=@telephone AND @telephone IS NOT NULL) "+
"OR ((family = @family AND name = @name) AND @telephone IS NULL)";
SqlCommand cmd = SqlCommand(mySearch, myConnection);
cmd.Parameters.Add("@telephone", telephoneNumber);
cmd.Parameters.Add("@name", name);
cmd.Parameters.Add("@family", family);
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
}
From the code above telephoneNumber needs to be an object as it needs to be able to supply a System.DBNull.Value in place of the number. You could set this up like this:
object telephoneNumber;
if (telephoneNumberTextBox.Text == "")
telephoneNumber = System.DBNull.Value;
else
telephoneNumber = telephoneNumberTextBox.Text;
By the way, I'm not sure storing a telephone number as a decimal is the best approach. Certainly I've always stored them as strings and I've never seen them stored in any numeric format. How do you deal with phone number that start with a zero, or international numbers that are stored with a country independent prefix of +, or special service phone numbers that include the * or #.
Does this help?
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
Thanks in advance !!;)
mostafa hosseiny b.
|
|
|
|
|
manije wrote:
Thanks in advance
Are you a time traveller??
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
yes , and I do'nt Know , How do you understand .
Ofcourse , your guide , was very good and my means , was the same I want .
'@myVar IS NULL' .
Thanks again , but instead of using
'@myVar' , I use field name directly and I'd no problem but Really I do'nt know,How can Use with
'@'=variable in sql in c# .
Thanks,again .
mostafa hosseiny b.
|
|
|
|
|
I'll repeat my example with greater annotation:
string mySearch = "SELECT * "+"FROM MyTable "+
"WHERE (telephone=@telephone AND @telephone IS NOT NULL) "+
"OR ((family = @family AND name = @name) AND @telephone IS NULL)";
SqlCommand cmd = SqlCommand(mySearch, myConnection);
cmd.Parameters.Add("@telephone", telephoneNumber);
cmd.Parameters.Add("@name", name);
cmd.Parameters.Add("@family", family);
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
}
manije wrote:
but instead of using @myVar, I use field name directly and I'd no problem
These are two separate things. I cannot see how that would work without seeing your code. I suspect that there is some confusion with terminology here.
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
My Means is :
I do'nt know About variable in sql (like this :@telephone), or atleast I do'nt know,that what's
@telephone
in the code you wrote me(in c#).only I know ,it's a variable in SQL , but , How To Use!!!
thanks for patient .
mostafa hosseiny b.
|
|
|
|
|
To use a variable in SQL you must declare it first, then you can use it.
e.g.
-- First declare the variable
DECLARE @myIntegerVariable int
-- Now it can be used.
SET @myIntegerVariable = 12;
-- To get the result of a column in a SELECT statement that returns just one row.
SELECT @myIntegerVariable = COUNT(*) FROM MyTable;
-- To use as a filter in a SELECT statement
SELECT * FROM MyTable WHERE MyColumn = @myIntergerVariable
If the variable is arriving as a parameter into a stored procedure, then the definition of the procedure declared the varibale implicitly. e.g.
CREATE PROCEDURE dbo.MyProc
@myFirstParameter int,
@mySecondParameter varchar(20)
AS
-- Do the processing of the Stored Procedure
GO
In C# you can supply varibles as parameters to any SQL in the SqlCommand.CommandText . This was the version that I showed you already in the example in my previous post.
Does this help?
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
OK! And I Understand .
thanks again !
mostafa hosseiny b.
|
|
|
|
|
I have an typed collection wich is bounded to datagrid control like this:
dataGrid1.DataSource = collection;
How to disable 'new row' in DataGrid ?
object oriented
uml oriented
iconix oriented
sql oriented
truespace oriented
---
solitare oriented
|
|
|
|
|
airbus380 wrote:
How to disable 'new row' in DataGrid ?
Sorry if I missunderstood.
just do nothing in OnItemCreated event
<< >>
|
|
|
|
|
Check if your collection has a property called
AllowNew. Just set it to false.
|
|
|
|
|
I'm using MS Hierarchical FlexGrid to display hierarchical data from a database in a grid. As of now, I can't find out how to do that. I'm using Microsoft Visual C++ .NET 2003. I want to display data from two tables. One table has primary information, and the second table has multiple records for each record in the primary table. I'd like to display just the primary information and just let the user highlight a record to see what records in the second table belong to it. If anybody knows how to use the MSHFlexGrid (mshflxgrd.ocx... as opposed to the non-hierarchical one msflxgrd.ocx) and could offer any help, that'd be appreciated. Or if anybody knows how to solve this problem without mshflexgrid, that'd be great as well.
|
|
|
|
|
Lets see this can help
first filling records in grid
1.loop through the recordset
2.add a new blank row to the grid
3.keep a counter
4.use set_textmatrix(counter,colno) to fill records
now on click event of the datagird capture the row number that was clicked
use get_textmatrix to get the primary key value and show he data from the second table
|
|
|
|
|
Hi
I have a table as
mineralID year value
1 91 1000
2 91 2000
3 91 3000
1 92 500
2 92 300
3 92 8000
1 93 2000
2 93 1000
3 93 1100
I want to a table as
mineralID totalValue
1 3500
2 3300
3 12100
What should i do plz?
|
|
|
|
|
SELECT mineralID, SUM(value)
FROM MyTable
GROUP BY mineralID
The SUM() function tells the SQL Server to add together all the values in the value column, the GROUP BY tels SQL Server that rather than just a single total, you want a total for each mineralID .
Does this help?
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
If you want an upto date "table type" look at this data create a view
<br />
CREATE VIEW vw_Mineral_total<br />
AS<br />
SELECT mineralID, SUM(value)<br />
FROM MyTable<br />
GROUP BY mineralID<br />
If you want the Average
<br />
CREATE VIEW vw_Mineral_AVG<br />
AS<br />
SELECT mineralID, AVG(value)<br />
FROM MyTable<br />
GROUP BY mineralID<br />
|
|
|
|
|
Hi !
I have a variable (the following):
in Form1 we have:
....<br />
Public int myint;<br />
...<br />
private void btnOK_Click(object sender, System.EventArgs e)<br />
{<br />
....<br />
myint=4;<br />
...<br />
}
---
I Want to put this variable (myint) into the another variable (getmyint) in Form2.cs(formclass)
in form2 we have :
private void Form2_Load(object sender, System.EventArgs e)<br />
{<br />
....<br />
int getmyint;<br />
...<br />
} ---
How can I put the variable of form1(myint) into the variable in form2?
by the way, I made an object of the form1 in form2:
...<br />
Form1 getintform=new Form1();<br />
...<br />
private void Form2_Load(object sender, System.EventArgs e)<br />
{<br />
....<br />
int getmyint;<br />
getmyint=this.getintform.myint;<br />
...<br />
}
but I don't get any result , please guide me!
thanks!
mostafa hosseiny b.
-- modified at 3:39 Thursday 8th September, 2005
|
|
|
|
|
hi there,
because ur variable "myint" has not initialized yet in form1 constructor, so that's why u cannot get any result.
=> solution here:
1. should initialize the variable "myint" in form1 constructor
2. after creating form1 object in form2, just simply call it's btnOK_Click
Hope this helps
<< >>
|
|
|
|
|
can you help me please, how can write the initializing this variable "myint" in form1 ?
Yours !
mostafa hosseiny b.
-- modified at 7:55 Thursday 8th September, 2005
|
|
|
|
|
just simply assign ur variable in form1 constructor, somthing like this:
public form1()
{
myint = 4;
}
<< >>
|
|
|
|
|
thanks! but there is one difficult:
myint is in
btnOk_Click() Event and the value of this variable ,maby be vary ... ,
for example , everytime I run the application , the value of this variable maybe 1 OR 5 OR 8 and etc.
Yes , if we put a const value in the initializing for this , crtainly , we have no difficult but "myint" is in the btnOK_Ckick() Event.
guide me please!
thanks!
mostafa hosseiny b.
|
|
|
|