|
Here is the entire source that I have so far in this section:
ds = New DataSet
myCommand.Fill(ds, "Data")
id = ds.Tables("DATA").Rows.Count()
txtID.Text = id
strQuery = "INSERT INTO Events (ID, Code, Hour, Day, Location, Name, Cost) VALUES (" _
& Int(id) & ", '" _
& txtCode.Text & "', '" _
& txtTime.Text & "', '" _
& txtDate.Text & "', '" _
& txtLocation.Text & "', '" _
& txtName.Text & "', '" _
& txtCost.Text & "')"
cmd = New OleDbCommand(strQuery, myConnection)
cmd.ExecuteNonQuery()
|
|
|
|
|
The ID column, is Autonumeric ?
The Hour and Day Column, what type are they ?
Free your mind...
|
|
|
|
|
ID is standard number. Handling the increment in code.
All other columns are text.
|
|
|
|
|
I don't see nothing wrong with your select statement.
Did you check the size of the fields ?
What's the error description ?
Free your mind...
|
|
|
|
|
Are you repeating a value on a column that is indexed as primary key ?
Free your mind...
|
|
|
|
|
Uhhhm, no. And no. In fact, right now that table is empty. And everything is configured as a text value. I was really hoping it was the SQL, but now it looks like maybe the code itself. Or something else. Funny thing. That exact same code (with different fields and parameters) works perfectly in the same database, different table.
I'll have to look at it more thoroughly, I guess.
Thanks
|
|
|
|
|
One possibility is that Access requires literal date data to be set off by #, as in #11/03/2004#. This may apply to time values, as well, though Clippy won't tell me that no matter how hard I ask.
"Another day done - All targets met; all systems fully operational; all customers satisfied; all staff keen and well motivated; all pigs fed and ready to fly" - Jennie A.
|
|
|
|
|
Do you have a specific error message?
What is the schema definition of the Events table? (what are the field types and sizes for each field in the table)
Any identity/autogenerated columns? Is there primary key defined?
|
|
|
|
|
How can I get a list of tables from a SQL server database so that I can then display the list in a Repeater or DataList control? I would also like to get the Table Description property. My ultimate goal is to display my lookup tables (all begin with zlk) with hyperlinks that open forms for maintaining these tables.
|
|
|
|
|
select * from sysobjects where type='U' will return the tables...
Free your mind...
|
|
|
|
|
At my company, we have a SQL database that contains information about employees, clients, and other such administrative information. I'm developing an application that requires its own SQL database. One of the main tables has several fields that need to 'point' to valid records in the administration database, such as ClientID, for example.
How can I go about doing this? Can I add this somehow to my relationship diagram?
Thanks in advance.
Kyosa Jamie Nordmeyer - Cho Dan
Portland, Oregon, USA
|
|
|
|
|
MS SQL Server doesn't support creating relations to external datasources.
Though you are able to JOIN to external tables in a query.
Have a look at my latest article about Object Prevalence with Bamboo Prevalence.
|
|
|
|
|
Figures. Maybe that add that ability in Yukon. From a user standpoint, it seems like an obvious thing to include (my company can't be the first to want seperate databases for seprate needs), but who knows how tricky it is to program from Microsoft's side.
Oh well. Here's hoping for Yukon...
Kyosa Jamie Nordmeyer - Cho Dan
Portland, Oregon, USA
|
|
|
|
|
I am having trouble storing the date in UK format.
I have an aspx page with a DateTime Validator control - works ok.
If the Date Text field on the page is entered in US format: mm/dd/yyy my INSERT works fine. However iif the format is UK: dd/mm/yyyy, the INSERT fails.
So i got to thinking i should be formatting the date myself after it passes through the Validator.
i tried the code below:
dt = Convert.ToDateTime(txtBirth.Text);
output = dt.ToString("d",DateTimeFormatInfo.InvariantInfo);
values.Add("'" + output + "'");
Is this the correct approach? (full listing shown below)
If i do: //values.Add("'" + txtBirth.Text + "'");
and the Date is in US format it works fine, but fails for UK.
your help would be greatly appreciated...
Carl
Full Listing + stuff i've tried:
SqlConnection con;
string sql;
SqlCommand cmd;
StringBuilder sb = new StringBuilder();
ArrayList values = new ArrayList();
sb.Append("INSERT INTO [Users] ");
sb.Append("(UserID,Login,Password,FirstName,LastName,PhoneNumber,Email,Address,");
sb.Append(" MobileNumber, DateOfBirth,IsAdministrator) ");
sb.Append("VALUES ('{0}', '{1}', '{2}', '{3}','{4}','{5}','{6}','{7}','{8}',{9},{10})");
values.Add(Guid.NewGuid().ToString() );
values.Add(txtUser.Text);
values.Add(txtPwd.Text);
values.Add(txtFName.Text);
values.Add(txtLName.Text);
values.Add(txtPhone.Text);
values.Add(txtEmail.Text);
//values.Add(0);
if(txtBirth.Text != string.Empty)
{
//test vars
string output="No Output";
DateTime dt;
dt = Convert.ToDateTime(txtBirth.Text);
output = dt.ToString("d",DateTimeFormatInfo.InvariantInfo);
values.Add("'" + output + "'");
//Test Blocks
//block 1
//DateTime dtNow = DateTime.Now;
//values.Add("'" + dtNow + "'");
//block 2
//values.Add("'" + txtBirth.Text + "'");
//block 3
//values.Add("'27/11/1999'");
//block 4
//storing the date & time local to the client
//DateTime dt;
//dt = DateTime.Now;
//string output = dt.ToString("G",DateTimeFormatInfo.CurrentInfo);
//values.Add("'" + dt + "'");
//block 5
//dt = Convert.ToDateTime(txtBirth.Text);
//output = dt.ToString("d",DateTimeFormatInfo.InvariantInfo);
//values.Add("'" + output + "'");
//block 6
//values.Add("'" + txtBirth.Text + "'");
//test stuff
Label1.Text = output;
}
else
values.Add("Null");
|
|
|
|
|
I suggest either using DateTime.Parse, or using separate entry fields for day, month and year.
|
|
|
|
|
I suggest use Globalization Classes in .Net
using System.Globalization<br />
using System.Threading<br />
in page load
<br />
string slang = Request.UserLanguages[0];<br />
Thread.CurrentThread.CurrentCulture = new CultureInfo(slang);<br />
With this code according to user preferences you should be able to save datetime properly. If user is american it expect american style, if it is turkish then it expects turkish style. Request.UserLanguages[0] gives you a
string in this format
en-UK or en-US
first two chars is about language
second two chars is about culture.
You can check user culture and call different function according to that also.
Education is no substitute for intelligence. That elusive quality is defined only in part by puzzle-solving ability. It is in the creation of new puzzles reflecting what your senses report that you round out the definition. Frank Herbert
|
|
|
|
|
I suggest storing the date as a double. It is the way a computer stores it anyhow. You can't make a mistake when the user changes regional settings e.g. dd/mm/yyyy i.s.o. yyyy-mm-dd
Use a double and format it later for display purposes.
Grtz, Guus
|
|
|
|
|
Fun situation: We have been asked to convert an Access application to ASP.NET. The chap who wrote it eloped with the source code and so all we have is the database and compiled front-end.
The Access application has SQL 6.5 as it's back-end with just Access as the front-end (an ADE file).
We are running SQL 2000 and the database copies over fine from SQL 6.5.
The problem comes when we want to try and run this ADE file on our network as opposed to the clients. With some help from David Wulff (thanks mate!) I have managed to HEX edit the connection string. It was a stroke of luck that our named pipe was the same length as the original. So that is changed.
But I have no clue about SQL named pipes. How do I make our SQL 2000 box accept this connection type?
Here is the pipe: \\BGCTNT01\PIPE\SQL\QUERY
regards,
Paul Watson
Bluegrass
South Africa
Brian Welsch wrote:
"blah blah blah, maybe a potato?" while translating my Afrikaans.
Crikey! ain't life grand?
Einstein says...
|
|
|
|
|
In Enterprise Manager, right-click your server, choose Properties. At the bottom of the General tab, click Network Configuration. Find 'Named Pipes' in the Disabled Protocols list, select it, then click Enable. OK out of all the boxes.
You need to stop and restart the server for the change to take effect.
|
|
|
|
|
hi there
Is there any way (method or a built-in procedure in sql) to find out which databases are included in a specific ms sql server.I know the ip address of the ms sql server and i want to write a method in C# to list the available databases.Can you give me an example code?
thank you in advance
fotis
greece
|
|
|
|
|
just write a select statement to get a list of all the databases located in a server
make sure to connect to the 'master' database
select * from sysdatabases
|
|
|
|
|
I have the following code:
<br />
<br />
try<br />
{<br />
string ConnString;<br />
ConnString="Provider=SQLOLEDB;";<br />
ConnString+="data source=127.0.0.1;";<br />
ConnString+="initial catalog=AutoConvert;";<br />
ConnString+="password=password;";<br />
ConnString+="persist security info=False;";<br />
ConnString+="user id=sa;";<br />
OleDbConnection dbConn = new OleDbConnection(ConnString);<br />
dbConn.Open();<br />
<br />
FileStream fs = File.Open("c:\\temp\\output.dat",FileMode.Open);<br />
BinaryReader BR = new BinaryReader(fs);<br />
byte [] BLOB=BR.ReadBytes(Convert.ToInt32(fs.Length));<br />
DataBase.InsertBLOB(dbConn,"Documents","BatchName","1234567",true,"Document",BLOB);<br />
dbConn.Close();<br />
<br />
}<br />
catch(Exception Err)<br />
{<br />
Console.WriteLine(Err.Message);<br />
}<br />
<br />
<br />
<br />
<br />
static public void InsertBLOB(OleDbConnection db,string Table,string LookUpField,string LookUpData,bool IsLookUpString,string BLOBField,byte [] BLOB)<br />
{<br />
try<br />
{<br />
string Command;<br />
if(IsLookUpString)<br />
Command= String.Format("UPDATE {0} SET {1}=@{1} WHERE({2}='{3}')",<br />
Table,BLOBField,LookUpField,LookUpData);<br />
else<br />
Command= String.Format("UPDATE {0} SET {1}=@{1} WHERE({2}={3})",<br />
Table,BLOBField,LookUpField,LookUpData);<br />
OleDbCommand addEmp = new OleDbCommand(Command, db); <br />
addEmp.Parameters.Add("@"+BLOBField,BLOB);<br />
addEmp.ExecuteNonQuery();<br />
}<br />
catch(Exception Err)<br />
{<br />
throw new Exception(Err.Message);<br />
}<br />
}
addEmp.ExecuteNonQuery throws an exception witht he message:
"You must define @Document"
I copied the code almost directly from MSDN, but I can't get it to work...Any ideas ?
Oh and in my AutoConvert Catalog I have the table Documents with an image field of length 16 called Document.
|
|
|
|
|
From the OleDbCommand.CommandText documentation:
"The OLE DB .NET Provider does not support named parameters for passing parameters to an SQL Statement or a stored procedure called by an OleDbCommand when CommandType is set to Text. In this case, the question mark (?) placeholder must be used."
If you're talking to SQL Server (7.0 or 2000), use the SqlConnection and SqlCommand classes instead. Otherwise, replace the named parameter in the command text with a ?.
|
|
|
|
|
Thanks for the info, I was still wondering how it was done with OleDb...thanks.
|
|
|
|
|
Hi-
I'm a real beginner, so be gentle with me.
I'm trying to write a store procedure that basically takes value from Database A and insert it into Database B. Can someone give me an example of how to do this please?
Thanks!
|
|
|
|
|