private void Page_Load(object sender, System.EventArgs e)
{
String Sql = "INSERT INTO ssUser (UID, UserID, UserPwd) VALUES ('1', '2', '2')";
Sql = Sql.Substring(Sql.IndexOf("INTO") + 4);
string table = Sql.Substring(0,Sql.IndexOf("("));
string psv = Sql.Substring(Sql.IndexOf("VALUE"));
Hashtable ht = new Hashtable();
string[] Psn = SubString(Sql,"\\(","\\)").Split(',');
string[] Psv = SubString(psv,"\\(","\\)").Split(',');
this.Response.Write(Psn[1] + ":" +Psv[1]);
}
/// <summary>
/// 返回字符串的字串
/// </summary>
/// <param name="s1">被处理的字符串</param>
/// <param name="startSign">开始标记</param>
/// <param name="endSign">结束标记</param>
/// <returns>返回字串</returns>
private string SubString(string s1,string startSign,string endSign)
{
return System.Text.RegularExpressions.Regex.Match(s1, startSign + "(.*?)" + endSign).Result("$1");
}
OleDbConnection cnn = new ...;
OleDbDataAdapter da = new ....("select * from table1",cnn);
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
DataTable dt = new ...
da.Fill(dt);
//通过PrimaryKey属性取主键
Response.Write(dt.PrimaryKey[0].ColumnName);