数据贮存的问题,分不是很多
有几个texBox控件,客户在里面填好数据,按下button后如何把这些数据存入文档中.有这样的代码不.给我看看.
------解决方案-------------------- private void Collect_Add_Click(object sender, System.EventArgs e)
{
// 读入添加数据 还没考虑验证功能!!!!!
m_ProcureName = ProcureName.Text.Trim();
m_ProcureUrl = ProcureUrl.Text.Trim();
m_CollectUrl = CollectUrl.Text.Trim();
m_ServerType = ServerType.SelectedItem.ToString().Trim();
m_Regex = Regex.Text.Trim();
// MessageBox.Show(m_ProcureName+m_ProcureUrl+m_CollectUrl+m_ServerType+m_Regex);
// try
// {
// SqlConnection conn = new SqlConnection( "server=127.0.0.1;database=Info;uid=sa;pwd=sa; ");
// conn.Open();
// SqlCommand cmd = new SqlCommand( "insert into Info_Collect(Collect_PName,Collect_URL,Collect_Type,Collect_Address,Collect_Regex) values( ' "+m_ProcureName+ " ', ' "+m_ProcureUrl+ " ', ' "+m_ServerType+ " ', ' "+m_CollectUrl+ " ', ' "+m_Regex+ " ') ",conn);
// cmd.ExecuteNonQuery();
// conn.Close();
// MessageBox.Show( "插入成功!! ");
// }
// catch(Exception err)
// {
// MessageBox.Show(err.ToString());
// }
// 添加数据到数据库
try
{
string add = "insert into Info_Collect(Collect_PName,Collect_URL,Collect_Type,Collect_Address,Collect_Regex) values( ' "+m_ProcureName+ " ', ' "+m_ProcureUrl+ " ', ' "+m_ServerType+ " ', ' "+m_CollectUrl+ " ', ' "+m_Regex+ " ') ";
int i;
i = DbManagerSQL.ExecuteSql(add);
if(i == 1)
MessageBox.Show( "添加成功 ");
else
MessageBox.Show( "添加失败 ");
}
catch(Exception err)
{
MessageBox.Show(err.ToString());
}
}
------解决方案--------------------要求文档格式没?
XML?
------解决方案--------------------数据库操作::
public static int ExecuteSql(string SQLString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand(SQLString,connection))
{
try
{
connection.Open();
int rows=cmd.ExecuteNonQuery();
return rows;
}
catch(
System.Data.SqlClient.SqlException E)
{
// throw new Exception(E.Message);
MessageBox.Show(E.ToString());
return 0;
}
}
}
}