Storing data in SQL Server 2000

  • Thread starter Gustaf Liljegren
  • Start date
G

Gustaf Liljegren

In collecting user data from an InfoPath form, that is stored in SQL Server
2000. I got it working, but I doubt I've found the most straightforward
solution. From InfoPath, the data is transported in XML to a Web Service,
written in C#. The Web Service collects the data and does a few tricks on
it, before it is sent to the database. Here's the code:

[WebMethod]
public void ToDB(int x, int y)
{
SqlConnection sqlCon = new SqlConnection();
sqlCon.ConnectionString = "my connection string here";
CreateMySqlCommand("INSERT INTO Prospects
(FirstName, LastName) VALUES (" + x + ", " + y + ")", sqlCon);
}

public void CreateMySqlCommand(string myExecuteQuery,
SqlConnection myConnection)
{
SqlCommand myCommand = new SqlCommand(myExecuteQuery,
myConnection);
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
}

The input here is only int x and int y. In reality however, there will be
about 30 fields. Is there a better way to write it than a looong INSERT
statement?

I'm also wondering about the connection string. I know it's lame to store
login data in the source code. But what alternatives do I have? Sorry for my
ignorance. This must be a FAQ. :)

Thanks,

Gustaf
 
G

Gustaf Liljegren

NULL said:
Why would you separate these two methods? why not place the content
of CreateMySqlCommand in the 'ToDB'-method? (Just wondering)

You're right. I just cut and pasted the CreateMySqlCommand from a help file.
You could store it in the app.config file of your application
check out your local MSDN lib on 'AppSettingsReader'
(System.Configuration.AppSettingsReader)

Thanks, I'll check it.

Gustaf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top