exec sql include sqlca
int main(){
exec sql begin declare section
char userpasswd[30]="openlab/123456"
struct{
int id
char name[30]
double salary
}emp
exec sql end declare section
exec sql connect:userpasswd
exec sql declare empcursor cursor for
select id,first_name,salary from
s_emp order by salary
exec sql open empcursor
exec sql whenever notfound do break
for(){
exec sql fetch empcursor into :emp
printf("%d:%s:%lf\n",emp.id,emp.name,
emp.salary)
}
exec sql close empcursor
exec sql commit work release
}
把数据存到结构体里。
private void GetDataByParmSqlCommand()\x0d\x0a{\x0d\x0aSqlConnection sqlc = new SqlConnection(DBUtility.SqlHelper.ConnectionStringLocalTransaction) //取连接字符串饼建立sqlconnection\x0d\x0atry\x0d\x0a{\x0d\x0a\x0d\x0asqlc.Open()\x0d\x0aSqlCommand com = new SqlCommand("select * from c6 where usr_id = usr_id", sqlc)\x0d\x0aSqlParameter parm = new SqlParameter()\x0d\x0aparm.ParameterName = "@usr_id"\x0d\x0aparm.Value = "01\x0d\x0acom.Parameters.Add(parm)\x0d\x0acom.ExecuteNonQuery()\x0d\x0aDataSet ds = new DataSet()\x0d\x0aSqlDataAdapter sda = new SqlDataAdapter(com)\x0d\x0asda.Fill(ds, "c6")\x0d\x0aDataTable dt = ds.Tables[0]\x0d\x0atextbox.Text ="用户代码:"+ dt.Rows[0]["usr_id"].ToString().Trim() +"用户名称:"+ dt.Rows[0]["usr_name"].ToString().Trim() \x0d\x0a//这样组合一下就可以了,看你要显示哪些信息\x0d\x0a\x0d\x0a}\x0d\x0acatch (Exception ee)\x0d\x0a{\x0d\x0aMessageBox.Show(ee.Message, "")\x0d\x0a}\x0d\x0afinally\x0d\x0a{\x0d\x0asqlc.Close()\x0d\x0a}\x0d\x0a}int CountLines(char *filename) { ifstream ReadFileint n=0char line[512]ReadFile.open(filename,ios::in)//ios::in 表示以只读的方式读取文件 if(ReadFile.fail())//文件打开失败:返回0 { return 0} else//文件存在 { while(!ReadFile.eof()) { ReadFile.getline(line,512,'\n')n++} return n}欢迎分享,转载请注明来源:内存溢出
评论列表(0条)