|
You can use the DTS wizard that comes with SQL Server to import the data into SQL Server...
Store your favourite bookmarks online: my-faves.co.uk
|
|
|
|
|
Hi
I need some Help. I want to filter Records from one Table.
I got a new Form with two TextBoxes and one DataGrid. The
DataGrid shows the Results after Click on the Button named "Find".
One Textbox is for the DataBase ID. The other TextBox is for common
Text.
Now i need to assign the entered Text from the Textboxes to the sql String.
I hope you know what i mean cause my English is little bit bad sometimes.
I got the following Code and it works.. but how can i assign the text to the
sql Query? So it is static.
private void find ()
{
ds = new DataSet();
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=...
OleDbConnection conn = new OleDbConnection(ConnectionString);
OleDbCommand cmd = new OleDbCommand("SELECT * FROM tbl_Artikel WHERE ID =88 OR Hersteller LIKE 'Asus' OR Hersteller LIKE ''",conn);
dbAdapter = new OleDbDataAdapter(cmd);
dbAdapter.Fill(ds, "tbl_Artikel");
dataGrid1.DataSource = ds.Tables["tbl_Artikel"].DefaultView;
}
private void btFind_Click(object sender, System.EventArgs e)
{
find();
his.dataGrid1.AlternatingBackColor=Color.Wheat;
}
I tougt something like that, ("SELECT * FROM tbl_Artikel WHERE ID='"+this.textBoxID+"'",conn);
but it don't work furthermore i've heard this is no good solution.
What can I do???
|
|
|
|
|
realmontanakid wrote:
I tougt something like that, ("SELECT * FROM tbl_Artikel WHERE ID='"+this.textBoxID+"'",conn);
but it don't work furthermore i've heard this is no good solution.
That is correct. It is vunerable to SQL Injection Attack. Here is more information about preventing SQL Injection Attacks[^]
What you should do is create parameterised queries.
This means that your command will be something like this:
OleDbCommand cmd = new OleDbCommand("SELECT * FROM tbl_Artikel WHERE ID = ? OR Hersteller LIKE ?",conn);
cmd.Parameters.Add("@id", this.textBoxID.Text);
cmd.Parameters.Add("@hersteller", this.textBoxHersteller.Text);
DISCLAIMER: I am not familiar with exact Access syntax so the above is a guide only. The ideas are correct; the exact implementation may not be correct. For more information on see MSDN: OleDbCommand.Parameters[^]
Do you want to know more?
WDevs.com - Member's Software Directories, Blogs, FTP, Mail and Forums
|
|
|
|
|
Oracle has got a package called DBMS_SESSION that allows session data to be stored against a connection.
Does SQL Server 2000 have an equivalent feature?
Thanks.
|
|
|
|
|
Hello,everyone
Now i am working with dts,and i want to import data from different catalog to sqlserver,i find it can be implemented through setting globalvariables,and i pass the path to the initial catalog in my program.
Is there anyone who can give me some information on it?Anything will be appreciated .Thanx in advance!
|
|
|
|
|
I have a Dataset with a boolean field that contains a Null value extracted from the db. How can we know it's null ? I convert it to object, and checking against DBNull.Value, and all that stuff, and i can't find a way to do it.
Thanks in advance
Well.. later
|
|
|
|
|
How does Microsoft ObjectSpaces compare to other persistance layer frameworks (like Gentle.NET, iBATIS, nHibernate and so on) ? I been reading blogs and forums for some time and many people feel negative about it, although I suspect it's just because it's from MS.
|
|
|
|
|
I have a static database (well at least for as long as this software runs) and I wondering if any one know if it is better to load all the relevant data into a dataset first and then just work off that the rest of the program or to do many direct hits, returning two or 3 rows at a time, using DataReader?
I’m very new to databases and I’m probably missing some case info that may make a difference. If so, please let me know and I’ll try to be more specific.
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
HahnTech Affiliated With Code Constructors
Edmonton, Alberta, Canada
Email: rhahn82@telus.net
|
|
|
|
|
Generally the most efficient in terms of performance is to retrieve only the data that you need.
Whether you use DataSets or DataReaders is more a matter of your programming style, or the nature of the project (small vs large). DataSets are really nice if you are not planning on using business entity objects. If you are planning on using objects, then datareaders are probably a better bet.
If you are new to data access programming, I would say that you should either use DataSets, or use an OR Mapper, such as NHibernate.
my blog
|
|
|
|
|
Hi
I'm from Germany and got a little Problem.
I'm Writing a little Windows Application in C#.
It shows a Datagrid from one Table. Over textboxes
i can add or change Records. Further I can delete
Records. Now the Problem. The Datagrid is in the
first Form. What i need is another Datagrid, in another
Form by clicking on a menuItem. By Click on the MenuItem
the Form is shown but the DataGrid is empty! How can I realize this?
I'm sorry for my fearsome English, but I have no Time;)
FormFilter(MenuItem) is called from the main Function like this:
public FormFilter frm3;
private void miFilter_Click(object sender, System.EventArgs e)
{
frm3=new FormFilter();
frm3.Show();
}
Code FormFilter:
namespace DatabaseAccessWithADONET
{
///
/// Summary description for FormFilter.
///
public class FormFilter : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button btExit;
//DataFilterClass dfc = new DataFilterClass();
//public CurrencyManager currManager;
private DataSet ds;
private System.Windows.Forms.DataGrid dataGrid2;
private OleDbDataAdapter dbAdapter;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public FormFilter()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormFilter));
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btExit = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.dataGrid2 = new System.Windows.Forms.DataGrid();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.btExit);
this.groupBox1.Controls.Add(this.textBox2);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(8, 24);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(248, 184);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Filter";
//
// btExit
//
this.btExit.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btExit.Location = new System.Drawing.Point(136, 136);
this.btExit.Name = "btExit";
this.btExit.TabIndex = 4;
this.btExit.Text = "Exit";
this.btExit.Click += new System.EventHandler(this.btExit_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(120, 56);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(120, 20);
this.textBox2.TabIndex = 3;
this.textBox2.Text = "";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(120, 24);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(120, 20);
this.textBox1.TabIndex = 2;
this.textBox1.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 56);
this.label2.Name = "label2";
this.label2.TabIndex = 1;
this.label2.Text = "Text";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 24);
this.label1.Name = "label1";
this.label1.TabIndex = 0;
this.label1.Text = "ID";
//
// dataGrid2
//
this.dataGrid2.CaptionText = "FilterResults";
this.dataGrid2.DataMember = "";
this.dataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid2.Location = new System.Drawing.Point(272, 24);
this.dataGrid2.Name = "dataGrid2";
this.dataGrid2.Size = new System.Drawing.Size(448, 256);
this.dataGrid2.TabIndex = 5;
this.dataGrid2.Click += new System.EventHandler(this.dataGrid2_Click);
//
// FormFilter
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(760, 382);
this.Controls.Add(this.dataGrid2);
this.Controls.Add(this.groupBox1);
this.Name = "FormFilter";
this.Text = "FormFilter";
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
this.ResumeLayout(false);
}
#endregion
public void FormFilter_Load(object sender, System.EventArgs e)
{
ds = new DataSet();
string stConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\..\\Artikel_db.mdb";
OleDbConnection conn = new OleDbConnection(stConnection);
OleDbCommand dbArtikel = new OleDbCommand("select * from tbl_Artikel",conn);
dbAdapter = new OleDbDataAdapter(dbArtikel);
dbAdapter.Fill(ds, "tbl_Artikel");
dataGrid2.DataSource = ds.Tables["tbl_Artikel"].DefaultView;
}
private void btExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
|
|
|
|
|
First you can implement a property or a function in your FormFilter (the 2nd form). Let's call it BindData().
BindData will be used to pass the datatable from the 1st form and to bind it to FormFilter.
public void BindData(DataTable dataTable)
{
myDataGrid.DataSource = dataTable.DefaultView;
}
[edit]You might need to pass the datatable as ref[/edit]
Then call the property/function before you show the 2nd form in miFilter
private void miFilter_Click(object sender, System.EventArgs e)
{
frm3=new FormFilter();
frm3.BindData(ds.Tables["tbl_Artikel"])
frm3.Show();
}
I haven't checked it so I'm not sure whether you can copy and paste the code, but the idea is something like that.
Cheers,
Edbert P.
Sydney, Australia.
|
|
|
|
|
I have a problem running the Sql Server as localhost. It accepts the loopback address 127.0.0.1 though, and it also accepts running with the computer name.
The problem is that the self installing starter kits from www.asp.net requires an MS Sql Server that runs under the name localhost.
Does anyone know how to solve this problem.
|
|
|
|
|
Can you run
ping localhost
and verify that it works?
Generally I'd expect specifying localhost to work, as well as 127.0.0.1
Can you try
isql -S localhost -E
or
isql -S localhost -U sa -P password
and see if they work?
At the risk of sounding patronising, can you be sure it's a connection issue, not that you haven't created any required tables, for instance...
Steve S
Developer for hire
|
|
|
|
|
Hi,everyone. i'm a newbie of VC,i'm sorry if the question bother you...
Here it is:
when i first added the Microsoft DataGrid Control, Version 6.0(OLEDB), and added a member variable to a class by Class Wizard. However, for some reason I didn't do it rightly, so I wanted to delete it. (I think i must delete it in a wrong way and left something!) I navigated to the variable in the header file, and I deleted it.
However, when I tried to reinsert the variable (once again by using Class Wizard, and choosing Add Member Variable), the former context menu didn't come out:
"The ActiveX Control "Microsoft DataGrid Control, Version 6.0(OLEDB)" has not been inserted into the project. Developer Studio will do this now and generate a C++ wrapper class for it." -- Dialog is expected.
instead, "Add Member Varible" dialog appears and the varible type datagrid1 exsits and i can't use it properly. i have searched in files i can't find string "datagrid" anymore,why does the compiler remember that
so i think i should reinsert the component,another question comes up:
why do they have "Project->Add to project->Components and Controls"
but don't have "Project->Minus to project->Components and Controls"
i don't know how to do,and hope someone can help me,and hope i describe the problem clearly...
Best wishes for all of you! and this is really a great place! i'm so enjoying being here and learn a lot! ^.^
Thank you! and Happy Thanksgiving!
You will when you believe!
|
|
|
|
|
i'm trying to restore a db from a windows app., but i had an error stating that the DB is in use and can't be restored.
can anyone help please ...
*********
CODE
********
public static void RestoreDB(string path)
{
string commandString="USE MASTER RESTORE DATABASE Guirguis FROM DISK = '"+path+"'"; //Guirguis : DB to restore
SqlConnection newConn=new SqlConnection();
newConn.ConnectionString="workstation id="+System.Environment.MachineName+";packet size=4096;integrated security=SSPI;data s" +"ource=\".\";persist security info=False;initial catalog=master";
command=new SqlCommand(commandString,newConn);
dbConnection.Close(); //connection may be using Guirguis
newConn.Open();
try
{
command.ExecuteNonQuery();
}
catch(Exception e)
{
newConn.Close();
throw new Exception(e.Message);
}
newConn.Close();
newConn.Dispose();
}
*******************
thanx
|
|
|
|
|
to restore a database you have to amke sure that there is no user currently logged into the database. Atleast in SQL Server you do.
So go into enterprise manage and check if ther are any users logged into before attempting a restore.
Kick the users out and then attempt the restore.
If it works then your code is fine , you jsut have to make sure that no user is using the db before attempting the restore
|
|
|
|
|
Hi,
I'm using the ADO.NET with C#. When I perform an SQL query on a table in which the primary key consists of multiple fields and the SQL query is done on fewer fields than the primary key I get an exception.
("No value given for one or more required parameters")
I get why this may not be allowed, but I could to this in the old ADO.
(let's say I want all the x's of y, then y & x consist of the primary key, but I still need to create a query that returns all the x's of a certain y)
Does anybody know if they changed that? or do I need to do something else.
Thanks!
|
|
|
|
|
Since you don't post your query or the C# code you are using to access it diagnosing the problem may be a little challenging.
sharonz wrote:
("No value given for one or more required parameters")
This indicates that there is a problem with the parameters you pass to the query rather than the query itself.
e.g.
SqlCommand cmd = new SqlCommand("MyStoredProc", connection);
cmd.Parameters.Add("@MyFirstParameter", someValue);
cmd.ExecuteNonQuery(); with the corresponding SQL
CREATE PROCEDURE dbo.MyStoredProc
@MyFirstParameter int,
@MySecondParameter int
AS
...
GO This would most likely give the same error message because you have missed one of the parameters.
If this does not give you the idea for the answer, please post the relevant code snippets.
Do you want to know more?
WDevs.com - The worlds first Developers Services Provider
|
|
|
|
|
Hi gurus,
I have created a blank Access database (mdb) and I would like to know how I can add a table, fields (columns) and records (rows) in C#.
Can anyone show me a sample code to do these operations please?
Best regards
There is no spoon.
|
|
|
|
|
I don't know Access specific syntax... But I can give some generic advice.
The OleDbCommand can accept just about any SQL string that you could give directly to the database. Therefore you just create your SQL and pass it to the command object then do command.ExecuteNonQuery() [as you don't require any results back] and it should work.
Do you want to know more?
WDevs.com - The worlds first Developers Services Provider
|
|
|
|
|
Anybody knows any good free data transformation tool and OLAP client tool? Thanks a lot.
<italic>Work hard and a bit of luck is the key to success. You don`t need to be genius, to be rich.
|
|
|
|
|
Grid only views Date part of a datetime objects(Fields) ...is there any mean to view the time part only or even both date and time.
thanx
Mr.Cooper
|
|
|
|
|
This probably belongs in the ASP.NET forum, but I'll take a stab at it anyway. I think you need to set the DataFormatString property of the appropriate BoundColumn object. Try, for example, setting it to {0:t} or {0:g} .
For more date/time formatting options, see Standard DateTime Format Strings[^] and Custom DateTime Format Strings[^] in the .NET Framework documentation.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Using the following code the first insert is ignored so only the 'y' and 'z' rows appear in the table. The table is empty before any of the inserts. Anybody know why this is happening? Is there an easier way of getting data into a table?
OleDbConnection cn = new OleDbConnection();<br />
cn.ConnectionString = @"Provider=Microsoft.JET.OLEDB.4.0;" +<br />
@"Data Source=" + sDBPath + ";" +<br />
@"Jet OLEDB:Engine Type=5";<br />
<br />
cn.Open();<br />
OleDbDataAdapter adap = new OleDbDataAdapter("SELECT * FROM Info",cn);<br />
OleDbCommand cmdInsert = new OleDbCommand();<br />
cmdInsert.Connection = cn;<br />
<br />
cmdInsert.CommandText = @"INSERT INTO Info (InfoDesc, InfoVal) VALUES (?, ?)";<br />
cmdInsert.Parameters.Add(new OleDbParameter("InfoDesc",OleDbType.VarWChar,50,"InfoDesc"));<br />
cmdInsert.Parameters.Add(new OleDbParameter("InfoVal",OleDbType.VarWChar,50,"InfoVal"));<br />
adap.InsertCommand = cmdInsert;<br />
<br />
DataSet ds = new DataSet();<br />
adap.Fill(ds,"Info");<br />
<br />
DataRow dr = null;<br />
dr = ds.Tables[0].NewRow();<br />
dr["InfoDesc"] = "x";<br />
dr["InfoVal"] = "x";<br />
ds.Tables[0].Rows.Add(dr);<br />
<br />
dr = ds.Tables[0].NewRow();<br />
dr["InfoDesc"] = "y";<br />
dr["InfoVal"] = "y";<br />
ds.Tables[0].Rows.Add(dr);<br />
<br />
dr = ds.Tables[0].NewRow();<br />
dr["InfoDesc"] = "z";<br />
dr["InfoVal"] = "z";<br />
ds.Tables[0].Rows.Add(dr);<br />
<br />
adap.Update(ds,"Info");<br />
ds.Dispose();<br />
cn.Close();>
Rugby League: The Greatest Game Of All.
|
|
|
|
|
I have a query which inserts data from one database to another. The two tables are identical. The problem is that when viewed through enterprise manager, you can see all the records(200 of them). However, when doing a select * in query analyser, it shows the results as 0. Has anyone ever come across this? If so, please let me know whats happening here. If you restart sql, you can then see the records in query analyser.
|
|
|
|
|