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
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