Reading And Writing To Databases

Jun 13, 2007

I am new to database programming. What I want to do is have a database on a clients PC to use as data storage. This program will connect to a program running on our server (via TCP) which will store this information in another database. The clients database will only be accessed by my program - so I think that I don't need to register it with SQLEXPRESS. The servers database will probably need to be so another program can access it.

The problem I was having was writing and reading to a database that I created inside Visual Studio 2005. As I see it, there could be three issues - reading, writing, or setup of the database. To find out this issue I downloaded the Northwind database. The code below returns column 0 row 0 of the Customers table.




Code Snippet

NORTHWNDDataSet northwindDataSet = new NORTHWNDDataSet();

NORTHWNDDataSetTableAdapters.CustomersTableAdapter customersTableAdapter = new NORTHWNDDataSetTableAdapters.CustomersTableAdapter();

customersTableAdapter.Fill(northwindDataSet.Customers);



string data = (string)northwindDataSet.Customers.Rows[0].ItemArray[0];
Console.WriteLine("COL 0 - ROW 0: " + data);

This code returns "ALFKI". Which is what is in col 0 row 0 (This can be checked by right clicking on the Customers table in NorthWNDdataset.xsd and selecting preview data).

Next is writing. This is where I have the issues. The method below is one way that I tryed.




Code Snippet

DataRow row = northwindDataSet.Customers.NewRow();
row[0] = "1";
row[1] = "2";
row[2] = "3";
row[3] = "4";
row[4] = "5";
row[5] = "6";
row[6] = "7";
row[7] = "8";
row[8] = "9";
row[9] = "10";
row[10] = "11";
northwindDataSet.Customers.Rows.Add(row);

try
{ customersTableAdapter.Update(northwindDataSet.Customers);//table);
northwindDataSet.AcceptChanges();
MessageBox.Show("Update worked");
}
catch
{
MessageBox.Show("Update do not work!");
}

The messagebox shows "Update worked" - yet the data did not get added.

Thanks in advance.

Using:
Visual Studio 2005
C#
SQL Server Management Studio Express

View 3 Replies


ADVERTISEMENT

Reading And Writing To Same Table

Feb 16, 2008

I need to select all the records in a table, loop through them one by one, calculating some new field data, and then write the new data back to the same table. Here is the basic structure of what I've come up with:<CODE>SqlCmd = SqlConn.CreateCommandSqlStatement = "SELECT ProductID, Name FROM tblProducts"SqlCmd.CommandText = SqlStatementSqlRdr = SqlCmd.ExecuteReaderIf SqlRdr.HasRows Then  While SqlRdr.Read    If SqlRdr.FieldCount > 0 Then      ...      SqlWriteCmd = SqlConn.CreateCommand      SqlStatement = "UPDATE tblProducts SET Name = '" & NewName & "' WHERE ProductID = " & CStr(ProductID)      SqlWriteCmd.CommandText = SqlStatement      SqlWriteCmd.ExecuteNonQuery()      SqlWriteCmd = Nothing    End If  End WhileEnd IfSqlRdr.Close()SqlCmd = Nothing </CODE>I get an error that tells me to close out the Reader before trying to execute the write query. But I can't close it out for the loop to work properly. So I assume that there must be another way to do this simple task, but I'm so new to all of this that I need some help! Thanks! 

View 1 Replies View Related

Reading / Writing Binary Data To Db

Sep 9, 2004

I'm trying to read a byte array of an image datatype from sql server, and then to put this in another field in the database. I get a byte array, but somehow the image doesn't get into the db well with the sql parameters. Does anyone have an idea how to tackle this problem?

Thanks a lot, Hugo

View 2 Replies View Related

Reading Or Writing A File To A SQL Database

Nov 22, 2004

Halo, I am a bit new to this
Please can someone help me, I would like to write a file(Any type) to a SQL database like a attached document(s) for the current record and be able to detatch the document when needed.
I use VB.NET for a ASP.NET app.
I basicly would like to attach documents to a piece of equipment may it be any kind and if the user views the equipment he will be able to detatch the documents for that piece of equipment and open it with the correct software.
PLEASE HELP!!!!!!!

View 1 Replies View Related

Reading And Writing Same Variable To A Script

Apr 27, 2006

It looks like its not possible to both read and write the same variable from a script using the conventional Me.Variables.<variable> syntax.

I can only assign a variable as Readonly or ReadWrite and not both. If I assign it ReadOnly I can only access it in the PreExecute subroutine. If I assign it ReadWrite I can only access it in the PostExecute subroutine (in fact doesn't this just make it WriteOnly in fact?). So I can only either read in or read out a variable using this syntax, noth both. Is this right?

So the read and write a variable to a script, the VariableDispenser approach is the only option to use. Is this right? and is it documented somewhere that this is how to use variables in scripts. Thanks.

View 13 Replies View Related

Reading Variabels From DTSX==&&>Writing

Jul 20, 2007

Hi,



I want to make an application that fills in the variables into a dtsx package (ssis).

I'm able to read the variables created in the package



Application app = new Application();

Package p = app.LoadPackage(pkg, null);

Connections myConns = p.Connections;



foreach( Variable v in p.Variables){

Console.WriteLine(v.Name);

Console.WriteLine(v.Value);

Console.WriteLine(v.Namespace);

Console.WriteLine("/////////////////////");

Console.WriteLine("/////////////////////");

}

i'm also able to add on

Variable myVar = p.Variables.Add("amyCustomVar", false, "User", "3")



When the applications is closed the package does not contain the variable. So this is all done in memory.

Is their a way to actually write the variable into the physical package.

View 1 Replies View Related

Reading/Writing Data From A SQL Database

Feb 14, 2008



Hi,
I have a data structure called 'Quote' which contains a number of different variables and controls ranging from text boxes, check boxes and radio buttons, i need to be able to read and write this from a database.

First I think a description of my overall project is needed:



Project Description
I have been given a brief that basically says: i have to create a programmed solution in VB to solve a problem. This problem can be anything we like, and I personally have chosen to create a program that manages quotes for building Log Cabins (this is very contrived and far from anything someone would do in the real world).

My solution will allow a generic user to create a quote (using a form with controls such as text boxes, check boxes, radio buttons) , and then save this to file. These users may then wish to load/edit this quote at a later date, from another form.

Whilst completing this project, i'll only have up to about 5 records (quotes) within the system, so i dont need the ability to store hundreds of records. And each record will be relatively short, with only about 10-15 data items within the data structure.

Also the Admin (or business owner in this case) need to be able to view all saved quotes in a presentable format, and edit them if needs be, from within this same program.

This solution does not need to be absolutely perfect and 100% efficiently coded, or have all the bells and whistles a real-world program would have. This is for an A level computing project by the way.





So basically, i need to be able to read from the database (to populate a Data Grid (i imagine this is best way?)) and so Admin can access any quote and edit it (editing is not vital, but viewing/printing is. Maybe i should stop at just viewing any quote?). Also i need generic users to be able to fill in the Edit Quote form and then save this data into the database.

And is a data structure really required for me to use a database?

I've never used databases in VB before (but have used them elsewhere, mainly Access) and so am completely new to this. Any help will be much appreciated.
Thanks

View 13 Replies View Related

Reading And Writing To Flat File

Apr 27, 2006

I'm doing a test package which reads a flat file, makes an adjustment using the derived column task and writes to the same flat file. But, the read locks the flat file, so the write can't access it. Any ideas for a resolution?

Thanks,
Dave

View 2 Replies View Related

Reading/writing Files To Network Drive

Mar 20, 2007

We have a package that is using a ForEach loop container to access files on a network drive. For some reason I am getting a message that the ForEach enumerator is empty and did not find any files that matched the pattern. For the pattern I left the default *.* for testing purposes. I have specified the file folder as \remoteserverfilesharesubfolder and also as \remoteserverc$filesharesubfolder and have gotten the same message. However when I map a network drive and set the file folder to the network drive it finds the files. Is this a permissions issue?

After I finish processing the file I want to move it to a new directory. Once this is deployed in production, the package will not be running under a domain account and probably won't have access to the network folder. Is there any way to specifiy in the connection manager itself that it should use a specific account to access the folder?



TIA,

Sabrina

View 1 Replies View Related

Reading SQL 6.5 Databases

Aug 23, 2001

I received a SQL Server 6.5 database (.dat file) on a removeable drive. I'm currently running 7.0. Is there any way to read/import/link to this data without installing 6.5. And if I have to install 6.5 how do I get the system to see the database?

View 1 Replies View Related

Linking Tables From Different Databases Or Querying From Multiple Databases

Dec 10, 2007

Dear Readers,Is it possible, like in Access, to link to tables in other SQL databases that are on the same server? I have a query that I originally had in Access that queered from multiply databases. It did this by having those other tables in the other databases linked to the database that had the query. 
 

View 3 Replies View Related

Service Broker Not Working For Restored Databases (SQL 2000 Databases Restored On 2005)

Jan 24, 2006

I just restored my SQL server 2000 database on the SQL server 2005. after this i ran the Service broker sample ("Hello World") on this database by changing the AdventureWorks name to the new database name. The "setup.sql" runs fine. When i run the "SendMessage.sql" i was not getting any rows in the output (The message was not getting inserted into the queue). I checked the Service broker is enabled on this databased using the query "select is_broker_enabled from sys.databases where name = 'newdbname' " It was 1. I even tried the ALTER DATABASE SET ENABLE_BROKER. but it didnt work.

When i tried the sample on a newly created database it worked fine.

Is there any solution to make the restored database to work for service broker.

Thanks

Prashanth

View 3 Replies View Related

New To Writing In SQL

Jun 21, 2008

I have some experience with MS SQL mostly installation, configuration, maintaining, etc. But I am trying to teach myself some TSQL. I have bought a few beginner books and have some test machines. In advance, I appreciate any feedback!

I have a database with two tables. I want to calc the min salary for a class of employees. The "wage" is in one table and the "status" is in another.

USE Database
GO
SELECT MIN(Wage) AS "Min Salary", Status
FROM Employee, Job
WHERE Status = '1'
GROUP BY Wage, Status
GO

The result set brings back all not the "status" class that I want.

Again, I am relatively new so take it easy on me!

Thanks,
grinch

View 4 Replies View Related

Writing To SQL Log

Mar 3, 2008



Hello,

I wrote a stored procedure in SQL 2K5, and I would like to write to the sql log without using a rasieerror function. I just would like to log the sucessfull steps without exiting the proc. I am not sure how to do this. Any help would be appreciated.

Thanks,

Dave

View 3 Replies View Related

Writing To SQL

May 13, 2007

Hi,



I am new to this programming and SQL.



I am following the: Lesson 8: Obtaining Data from a SQL Server 2005 Express Edition Database video series. I cannot get the following to write changes to the SQL Database:



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

BindingSource1.EndEdit()

'CustomerTableAdapter1.Update(MyCompanyDataSet1.Customer)

Dim rowsAffected As Integer = 0

rowsAffected = CustomerTableAdapter1.Update(MyCompanyDataSet1.Customer)

MessageBox.Show(rowsAffected.ToString())

End Sub

End Class





I do get the message box to popup showing 1 row of changes when I make one change, however that change does not get written to the database. Is this enough info to have any idea why?





Thanks

View 1 Replies View Related

Reading An Excel Doc

Jul 16, 2007

hi guys, Can anyone advise me how how to read an excel doc i have stored locally? I need to be able to start the read from say row number 6 and finish the read once i get to a row that contains a pre-determined  word signifying the end of processing. I intend to store the parsed data in an array that will be used as the data source for a gridview or repeater object on another asp page. I'm using ASP.net 2.0 and C# by the way. thanks in advance for any help!!! 

View 12 Replies View Related

DataReader Not Reading

Jan 13, 2004

Why won't this dataReader read?

Dim objCon2 As New SqlConnection()
objCon2.ConnectionString = "a standard connection string"
objCon2.Open()

Dim objCommand As SqlCommand
objCommand = New SqlCommand(strSQL, objCon2)
Dim objReader As SqlDataReader
objReader = objCommand.ExecuteReader()

Label1.Text = objReader("email")

strSQL is a select command which I've checked (using SQL Query analyzer) does return data. I know the connection string is valid (and I presume if it wasn't that it'd fail on objCon2.open, which it doesn't).

So why oh why do I get this error on the last line (and yes, there is an "email" field in the contents of the reader)

System.InvalidOperationException: Invalid attempt to read when no data is present.

View 1 Replies View Related

Help With Reading Database.

Jun 29, 2005

I have this code that I hacked together from someone else's example.  I kind of understand how it works.  I just don't know if it will and i am not in a location right now to check.  I was wondering if I did this correctly first, second how can it improve and should i do something different.  Basically i just want to check the password in a database. I am passing the username and password to this function from another functioprivate bool authUser(string UserName, string Password){ string connectionString = ConfigurationSettings.AppSettings["DBConnectionString"];  SqlConnection DBConnection = new SqlConnection(connectionString);  bool result = false;  DBConnection.open() SqlCommand checkCommand = new SqlCommand("SELECT password FROM Users WHERE userName='" + Password + "', DBConnection) SqlDataReader checkDataReader = checkCommand.ExecuteReader();
 if(checkDataReader.GetString(0) == Password) {  result = true; } else {  result = false; } checkDataReader.Close(); DBConnection.Close();
 return result;}Thank you Buddy Lindsey

View 6 Replies View Related

Reading Transaction Log

May 30, 2001

Does anyone know how to read transaction log besides trace and profiler. The current situation is some one in our org. deleted an item and I'm trying to find out who and when.

View 2 Replies View Related

Reading Log File

Feb 9, 2000

I have some records that have been deleted. I need to find out who did it and to do that I need to read the logs. Are there any utilities that will allow me to read login 7.0? How about 6.5?

Chris

View 2 Replies View Related

Reading The Transaction Log In SQL 7.0

Dec 22, 1999

Here is I think an interesting question
is there a way to read or access the transaction log of a
database in SQL server 7.0

Hoping someone has a solution :-)

View 5 Replies View Related

Reading The Transaction Log

Nov 2, 1999

We are having continual problems with our transaction log filling up on one of our major applications.
Does anyone know of a way or tool to read the transaction log? We want to determine what is causing this problem.

Thanks

View 3 Replies View Related

Reading The Transaction Log

Jul 12, 1999

Is there a way, in SQL 7.0 to print out or view what's in the Transaction Log? In 6.5 you could view the table syslogs, but I don't see any documentation anywhere on how to do this in 7.0.

View 1 Replies View Related

Reading Xml In A Sql Table

Apr 8, 2005

I receive in a table a field which is an xml string
like below

<NewOrder><SiteID>CJC</SiteID><patID>458887</patID><LName>Cronin</LName><FName>tim</FName><EntryID>{7B1A4946-CEC8-4F23-AE89-5C70A6A0F9B2}</NewOrder>

Is there a way read this field with a select statement? I need to strip out the entryid value in a trigger

View 4 Replies View Related

Reading MS-SQL Transaction Log

May 24, 2002

Hello people;


Somebody knows some utility where I can read the Transaction Log Sql 2000 ?

Thanks;


Navlig®

View 1 Replies View Related

Reading A Ini File In DTS

Jun 10, 2002

Hi

How can I read an ini file entry and pass this parameter to a stored procedure which will be run in a DTS Package?


Thanks for the input

mipo

View 2 Replies View Related

Reading DTS Packages

Sep 19, 2001

Anyone know a way to read DTS packages? I have inherited a DTS package, saved in SQL, and am trying to find a way to read the steps without having to view every single step through the GUI.

Thanks in advance.

View 3 Replies View Related

Reading ClientProcessID

Sep 1, 2006

Hi,

I need to know that how can we read ClientProcessID (älso use used in SQL Profiler).

Regards,
Shabber.

View 2 Replies View Related

Reading Results Into .NET

May 20, 2008

Hi. I want to write a function to retrieve all records from a "Parts" table so that I can read these records in .NET.

SqlDataReader reader = sqlCmd.ExecuteReader()

while( reader.Read() )
{
int x = reader["id"];
string partName = reader["name"];

// Do stuff with data here //
}


My question: How should the function be written?

Should I create a PROCEDURE and just call a SELECT statement?

CREATE PROCEDURE getPartsList()
AS
SELECT part_id as 'id', part_name as 'name' FROM parts


Or should I create a FUNCTION that returns a TABLE? If so, is this the correct syntax?

CREATE FUNCTION getPartsList()
RETURNS TABLE
AS
RETURN (SELECT part_id as 'id', part_name as 'name' FROM parts)


Thanks for reading

View 3 Replies View Related

Reading XML Element

Jun 9, 2014

The requirement is to read XML element from database column.The column looks like

<ClMetadataDataContract xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.cch.com/pfx.net/psi/">
<EntityType>1</EntityType>
<NameLine1>David Jones</NameLine1>

[code]....

I have also tries OPENXML but no luck

View 2 Replies View Related

Reading Log File

Jun 22, 2008

How do I view the SQL 2005 transaction log file(.ldf)?

Is there a built-in utility?

Thank you

View 3 Replies View Related

Reading A File

Jun 24, 2008

I am storing one text file on the server.This text file contains some mobile numbers.The file look like
009198XXXXXXXX
009198XXXXXXXX
009198XXXXXXXX
009198XXXXXXXX
etc

Here I need to read this text file row by row mobile number and then insert these mobile numbers into a table by using sql procedure or sql trigger or any other method or coding. Is it is possible or not?
If so then anybody can help me!

regards
Shaji

View 4 Replies View Related

Reading ID From XML File???

Jul 13, 2006

Hello friends...

We have sql server 2000 and i need to read one perticular xml and from that i want ID field stored in one table...is it possible by query analyzer to read xml and stored ID in table...I have only path of that xml file...



like



select ID from ("D:XMLFolder*.xml)



that i want

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved